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

Returns:

  • String



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

Returns:

  • (Boolean)


61
62
63
# File 'lib/fqdn_facts/core_ext.rb', line 61

def empty?
  !!(self !~ /\S/)
end

#underscoreObject

converts a camelized string to underscored

Returns:

  • String



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