Sha256: bd8c74745034dc8a517ee20e391f72c62419c414702137de6f9dd3ba58c5849f
Contents?: true
Size: 1.05 KB
Versions: 5
Compression:
Stored size: 1.05 KB
Contents
class CoreExt def self.constantize(camel_cased_word) names = camel_cased_word.split('::') names.shift if names.empty? || names.first.empty? constant = Object names.each do |name| constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name) end constant end def self.classify(underscored_word) words = underscored_word.split("_") words.each do |word| word.capitalize! end.join("") end def self.underscore(camel_cased_word) word = camel_cased_word.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 end class String def constantize CoreExt.constantize(self) end def classify CoreExt.classify(self) end def underscore CoreExt.underscore(self) end def ends_with?(patt) patt = Regexp.new(Regexp.escape(patt) + "$") self.match patt end end class Array def all_true? self.all? {|o| o == true} end end
Version data entries
5 entries across 5 versions & 1 rubygems