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
75 76 77 |
# File 'lib/fqdn_facts/core_ext.rb', line 75 def camelize self.split('_').collect(&:capitalize).join end |
#constantize(base = Object) ⇒ Object
Attempts to transform string into a class constant
80 81 82 83 84 |
# File 'lib/fqdn_facts/core_ext.rb', line 80 def constantize(base=Object) self.split('/') .collect(&:camelize) .inject(base) { |obj,klass| obj.const_get(klass) } end |
#empty? ⇒ Boolean
63 64 65 |
# File 'lib/fqdn_facts/core_ext.rb', line 63 def empty? !!(self !~ /\S/) end |
#underscore ⇒ Object
converts a camelized string to underscored
69 70 71 |
# File 'lib/fqdn_facts/core_ext.rb', line 69 def underscore self.split(/([A-Z][a-z0-9]+)/).reject(&:empty?).collect(&:downcase).join('_') end |