CamelCase in Ruby
Example for versions
Ruby 1.9
-
Read the string from standard input (
gets.chomp
) - Split the string into parts, separated with matches of regular expression, which describes a sequence of one or more non-letter characters
-
Apply to each part function
capitalise
-
Concatenate the resulting strings (
join
) and print the result (puts
)
puts gets.chomp.split( /[^a-zA-Z]+/ ).map {|w| w.capitalize}.join
Comments
]]>blog comments powered by Disqus
]]>