Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. line.gsub!(/^([A-Z ]+)/, '1'.capitalize)
  2.  
  3. line.gsub!(/^([A-Z ]+)/, "\1".capitalize)
  4.  
  5. line.gsub!(/^([A-Z ]+)/) { |w| w.capitalize }
  6.  
  7. require 'active_support'
  8. 'FOO bar'.gsub(/^[A-Z]+/) { |w| w.capitalize }
  9. => "Foo bar"
  10.  
  11. 'FOO bar'.gsub!(/^([A-Z ]+)/) { |w| w.capitalize }
  12. => "Foo bar"
  13.  
  14. 'FOO BAR'.gsub!(/^([A-Z ]+ [A-Z]+)/) { |w| w.capitalize }
  15. => "Foo bar"
  16.  
  17. 'FOO BAR'.gsub!(/^((?<word>[A-Z]+) g<word>)/) { |w| w.capitalize }
  18. => "Foo bar"
  19.  
  20. require 'active_support'
  21.  
  22. line = 'AFOO BFOO CFOO DFOO e f g'
  23. words = line[/^(?:[A-Z]+ )+/].split.map{ |w| w.capitalize } # => ["Afoo", "Bfoo", "Cfoo", "Dfoo"]
  24. [words,line.split[words.size..-1]].join(' ') # => "Afoo Bfoo Cfoo Dfoo e f g"
  25.  
  26. line.scan(/w+|W+/).map(&:capitalize).join
  27.  
  28. >> "FOO BAR foo BAR".gsub(/^([A-Z ]+)/,"#{$1.capitalize}")
  29. => "Foo bar foo BAR"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement