Sha256: 59a1bc872153160141935172016ec44a4a0de291f9daddb68c61ac93caafd39a
Contents?: true
Size: 1.46 KB
Versions: 38
Compression:
Stored size: 1.46 KB
Contents
# encoding: utf-8 ## Array class Array def all self end end ## String class String #:nodoc def permalink(underscore = false) # if the slug includes one "_" at least, we consider that the "_" is used instead of "-". _permalink = if !self.index('_').nil? self.to_url(replace_whitespace_with: '_') else self.to_url end underscore ? _permalink.underscore : _permalink end def permalink!(underscore = false) replace(self.permalink(underscore)) end alias :parameterize! :permalink! end ## Hash class Hash #:nodoc def underscore_keys new_hash = {} self.each_pair do |key, value| if value.respond_to?(:collect!) # Array value.collect do |item| if item.respond_to?(:each_pair) # Hash item within item.underscore_keys else item end end elsif value.respond_to?(:each_pair) # Hash value = value.underscore_keys end new_key = key.is_a?(String) ? key.underscore : key # only String keys new_hash[new_key] = value end self.replace(new_hash) end end class Boolean #:nodoc BOOLEAN_MAP = { true => true, "true" => true, "TRUE" => true, "1" => true, 1 => true, 1.0 => true, false => false, "false" => false, "FALSE" => false, "0" => false, 0 => false, 0.0 => false } def self.set(value) value = BOOLEAN_MAP[value] value.nil? ? nil : value end def self.get(value) value end end
Version data entries
38 entries across 38 versions & 1 rubygems