Class: String

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

Instance Method Summary collapse

Instance Method Details

#to_aObject



2
3
4
# File 'lib/core_ext/string.rb', line 2

def to_a
  [] << self
end

#to_numObject



6
7
8
9
10
11
12
13
14
# File 'lib/core_ext/string.rb', line 6

def to_num
  if !self.match(/^[0-9]+$/).nil?
    Integer(self)
  elsif !self.match(/^[0-9]+\.[0-9]+$/).nil?
    Float(self)
  else
    self
  end
end

#to_underscoreObject



25
26
27
28
29
30
31
# File 'lib/core_ext/string.rb', line 25

def to_underscore
  self.gsub(/::/, '/').
      gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
      gsub(/([a-z\d])([A-Z])/,'\1_\2').
      tr('-', '_').
      downcase
end

#to_vbox_object(cls) ⇒ Object



20
21
22
23
# File 'lib/core_ext/string.rb', line 20

def to_vbox_object(cls)
  return self if cls.nil?
  VBox.const_get(cls[1..-1]).new(self)
end

#vbox_classObject



16
17
18
# File 'lib/core_ext/string.rb', line 16

def vbox_class
  VBox::ManagedObjectRef.new(self).get_interface_name
end