Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/scale.rb,
lib/common.rb
Instance Method Summary collapse
- #camelize2 ⇒ Object
- #constantize2 ⇒ Object
- #hex_to_bytes ⇒ Object
- #underscore2 ⇒ Object
- #upcase_first ⇒ Object
Instance Method Details
#camelize2 ⇒ Object
77 78 79 |
# File 'lib/scale.rb', line 77 def camelize2 self.split('_').collect(&:upcase_first).join end |
#constantize2 ⇒ Object
32 33 34 |
# File 'lib/common.rb', line 32 def constantize2 Object.const_get(self) end |
#hex_to_bytes ⇒ Object
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 |
#underscore2 ⇒ Object
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_first ⇒ Object
73 74 75 |
# File 'lib/scale.rb', line 73 def upcase_first self.sub(/\S/, &:upcase) end |