Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/scale.rb,
lib/common.rb

Instance Method Summary collapse

Instance Method Details

#camelize2Object



77
78
79
# File 'lib/scale.rb', line 77

def camelize2
  self.split('_').collect(&:upcase_first).join
end

#constantize2Object



32
33
34
# File 'lib/common.rb', line 32

def constantize2
  Object.const_get(self)
end

#hex_to_bytesObject



36
37
38
39
40
# File 'lib/common.rb', line 36

def hex_to_bytes
  data = self.start_with?('0x') ? self[2..] : self
  raise "Not valid hex string" if data.length % 2 != 0
  data.scan(/../).map(&:hex)
end

#underscore2Object



81
82
83
84
85
86
87
# File 'lib/scale.rb', line 81

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

#upcase_firstObject



73
74
75
# File 'lib/scale.rb', line 73

def upcase_first
  self.sub(/\S/, &:upcase)
end