class String
Public Instance Methods
to_screaming_snake_case()
click to toggle source
# File lib/revision/string_case.rb, line 32 def to_screaming_snake_case dup.tap { |s| s.to_screaming_snake_case! } end
to_screaming_snake_case!()
click to toggle source
Converts _ScreamingSnakeCase to SCREAMING_SNAKE_CASE
# File lib/revision/string_case.rb, line 19 def to_screaming_snake_case! to_underscore! upcase! end
to_snake_case()
click to toggle source
# File lib/revision/string_case.rb, line 28 def to_snake_case dup.tap { |s| s.to_snake_case! } end
to_snake_case!()
click to toggle source
Converts SnakeCase to snake_case
# File lib/revision/string_case.rb, line 12 def to_snake_case! to_underscore! downcase! end
to_underscore()
click to toggle source
# File lib/revision/string_case.rb, line 24 def to_underscore dup.tap { |s| s.to_underscore! } end
to_underscore!()
click to toggle source
ruby mutation methods have the expectation to return self if a mutation occurred, nil otherwise. (see www.ruby-doc.org/core-1.9.3/String.html#method-i-gsub-21)
# File lib/revision/string_case.rb, line 3 def to_underscore! gsub!(/::/, '/') gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2') gsub!(/([a-z\d])([A-Z])/,'\1_\2') tr!("-", "_") end