For ex str="how to work in ruby on rails"
str.capitalize
=> "How to work in ruby on rails"
Now try this str.split(/\s+/).each{ |word| word.capitalize! }.join(' ')
=>"HowToWorkInRubyOnRails"
or
str.gsub(/^[a-z]|\s+[a-z]/) { |a| a.upcase }
=>"How To Work In Ruby On Rails
This article is based on ruby not on rails, since in rails titleize will be used to capitalize the first character of the sentence
No comments :
Post a Comment