Class: String

Inherits:
Object show all
Defined in:
lib/api_ai_wrapper/extensions/string.rb

Overview

String Override taken from Rails

Instance Method Summary collapse

Instance Method Details

#demodulizeObject



4
5
6
7
8
9
10
# File 'lib/api_ai_wrapper/extensions/string.rb', line 4

def demodulize
  if i = self.rindex("::")
    self[(i + 2)..-1]
  else
    self
  end
end

#underscoreObject



12
13
14
15
16
17
18
19
20
# File 'lib/api_ai_wrapper/extensions/string.rb', line 12

def underscore
  return self unless /[A-Z-]|::/.match?(self)
  word = self.gsub("::".freeze, "/".freeze)
  word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2'.freeze)
  word.gsub!(/([a-z\d])([A-Z])/, '\1_\2'.freeze)
  word.tr!("-".freeze, "_".freeze)
  word.downcase!
  word
end