Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/promoted/ruby/client/extensions.rb

Instance Method Summary collapse

Instance Method Details

#to_underscoreObject



8
9
10
# File 'lib/promoted/ruby/client/extensions.rb', line 8

def to_underscore
  dup.tap { |s| s.to_underscore! }
end

#to_underscore!Object

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)



3
4
5
6
# File 'lib/promoted/ruby/client/extensions.rb', line 3

def to_underscore!
  gsub!(/(.)([A-Z])/,'\1_\2')
  downcase!
end