Class: String
Overview
Instance Method Summary collapse
-
#camelize ⇒ Object
converts an underscored string to a camelized one.
-
#constantize(base = Object) ⇒ Object
Attempts to transform string into a class constant.
- #empty? ⇒ Boolean
-
#underscore ⇒ Object
converts a camelized string to underscored.
Instance Method Details
#camelize ⇒ Object
converts an underscored string to a camelized one
73 74 75 |
# File 'lib/fqdn_facts/core_ext.rb', line 73 def camelize split('_').collect(&:capitalize).join end |
#constantize(base = Object) ⇒ Object
Attempts to transform string into a class constant
78 79 80 81 82 |
# File 'lib/fqdn_facts/core_ext.rb', line 78 def constantize(base = Object) split('/') .collect(&:camelize) .inject(base) { |obj, klass| obj.const_get(klass) } end |
#empty? ⇒ Boolean
61 62 63 |
# File 'lib/fqdn_facts/core_ext.rb', line 61 def empty? !!(self !~ /\S/) end |
#underscore ⇒ Object
converts a camelized string to underscored
67 68 69 |
# File 'lib/fqdn_facts/core_ext.rb', line 67 def underscore split(/([A-Z][a-z0-9]+)/).reject(&:empty?).collect(&:downcase).join('_') end |