module Jaleb::String
This class extends string functions
Public Instance Methods
camelize(first_letter_in_uppercase = true)
click to toggle source
# File lib/jaleb/string.rb, line 8 def camelize(first_letter_in_uppercase = true) lower_case_and_underscored_word = self.dup.underscore if first_letter_in_uppercase lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase } else lower_case_and_underscored_word.first + camelize(lower_case_and_underscored_word)[1..-1] end end
constantize()
click to toggle source
# File lib/jaleb/string.rb, line 17 def constantize self.split("::").inject(Module) {|acc, val| acc.const_get(val)} end
sanitize()
click to toggle source
# File lib/jaleb/string.rb, line 4 def sanitize self.strip end
underscore()
click to toggle source
# File lib/jaleb/string.rb, line 21 def underscore word = self.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