Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/compositor.rb,
lib/compositor.rb
Instance Method Summary collapse
Instance Method Details
#constantize ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/compositor.rb', line 8 def constantize camel_cased_word = self unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ camel_cased_word raise NameError, "#{camel_cased_word.inspect} is not a valid constant name!" end Object.module_eval("::#{$1}", __FILE__, __LINE__) end |
#underscore ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/compositor.rb', line 21 def underscore self.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'). gsub(/([a-z\d])([A-Z])/, '\1_\2'). tr("-", "_"). downcase end |