Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/arnold/monkeypatch.rb
Instance Method Summary collapse
- #to_underscore ⇒ Object
-
#to_underscore! ⇒ Object
ruby mutation methods have the expectation to return self if a mutation occurred, nil otherwise.
Instance Method Details
#to_underscore ⇒ Object
10 11 12 |
# File 'lib/arnold/monkeypatch.rb', line 10 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)
6 7 8 |
# File 'lib/arnold/monkeypatch.rb', line 6 def to_underscore! gsub!(/(.)([A-Z])/,'\1_\2') && downcase! end |