Class: String

Inherits:
Object show all
Defined in:
lib/fqdn_facts/core_ext.rb

Overview

See Also:

Instance Method Summary collapse

Instance Method Details

#camelizeObject

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

#underscoreObject

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