From: sto.mar@... Date: 2013-05-09T04:56:03+09:00 Subject: Re: Recursion is not working well Am 08.05.2013 14:24, schrieb Love U Ruby: > 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? > Shorter is not automatically better. Your variable and method names are too short (!) and make reading of that code really painful. My recursive version (for strings, not symbols): def split_string(string) first, rest = string.split('_', 2) return [first] unless rest [first] + split_string(rest) end split_string('this_is_a_test') => ["this", "is", "a", "test"] More rubyish and even shorter (probably as short as possible) but not recursive: 'this_is_a_test'.split('_') :) --