Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/jasper-client/string.rb

Overview

Logic for both of these were lifted from the rails source tree. We don’t call active support directly because we didn’t want to depend on those gems merely for these two bits of functionality.

Instance Method Summary collapse

Instance Method Details

#humpifyObject



16
17
18
# File 'lib/jasper-client/string.rb', line 16

def humpify
  self.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
end

#underscoreObject



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

def underscore
  word = self.to_s.dup
  word.gsub!(/::/, '/')
  word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
  word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
  word.tr!("-", "_")
  word.downcase!
  word
end