Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/chemlab/core_ext/string/inflections.rb,
lib/chemlab/core_ext/string/root_module.rb
Overview
Start monkey patch of String
Instance Method Summary collapse
-
#classify ⇒ Object
Classify a string.
-
#root_module ⇒ Module
Find the root module (parent module) of a class or module.
-
#underscore ⇒ Object
Underscore a multi-worded string.
Instance Method Details
#classify ⇒ Object
Classify a string
10 11 12 |
# File 'lib/chemlab/core_ext/string/inflections.rb', line 10 def classify split('_').map(&:capitalize).join end |
#root_module ⇒ Module
Find the root module (parent module) of a class or module
10 11 12 |
# File 'lib/chemlab/core_ext/string/root_module.rb', line 10 def root_module Object.const_get(split('::').first) end |
#underscore ⇒ Object
Underscore a multi-worded string
19 20 21 22 23 24 |
# File 'lib/chemlab/core_ext/string/inflections.rb', line 19 def underscore chars.each_with_object(+'') do |c, str| str << '_' if c.match?(/[A-Z]/) && !str.size.zero? str << c.downcase end end |