From: Mike Stok Date: 2013-05-08T22:02:31+09:00 Subject: Re: Recursion is not working well On 2013-05-08, at 8:24 AM, Love U Ruby wrote: > Yes! I made it till now: > > s = :split_this_game_world > def brk(s) > cp = (s =~ /[_]/) > ss = s[0...cp] if cp != nil > return s.to_sym if cp == nil > return [].push(ss.to_sym,brk(s[cp+1,s.size - ss.size])).flatten > end > p brk(s) > > #=> [:split, :this, :game, :world] > > Is it possible to make it more shorter? > > -- > Posted via http://www.ruby-forum.com/. If you don't need recursion... [1] pry(main)> def brk(s) [1] pry(main)* s.to_s.split(/_/).map &:to_sym [1] pry(main)* end => nil [2] pry(main)> brk(:split_this_game_world) => [:split, :this, :game, :world] Mike -- Mike Stok http://www.stok.ca/~mike/ The "`Stok' disclaimers" apply.