one line to camelize underscore in Ruby
"foo_bar_zoo".split('_').to_enum.with_index.map{|s,i| i==0?s:s.capitalize}.reduce(:+)
and this, convenience for repeatedly.
loop do
puts gets.split('_').to_enum.with_index.map{|s,i| i==0 s:s.capitalize}.reduce(:+)
end
Written by Tiao Lims
Related protips
2 Responses
"foo_bar_zoo".gsub(/_(\w)/) { $1.upcase }
Well, it's easier with little bit of regexp magic :)
over 1 year ago
·
@ayakudere cool
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#