Reputation: 607
I have a string eg. String-aa. I want to be able to capitalise every letter after the "-". Is there a straightforward was of achieving this?
I am aware of .capitalize however dont know how to implement for this particular requirement.
Upvotes: 0
Views: 23
Reputation: 23711
You can make use of block form of gsub
"String-aa-bbbb".gsub(/-\w+/){|e| e.upcase}
#=> "String-AA-BBBB"
The above code will capture a letter followed by -
and will capitalize it
Upvotes: 1