class Hash
Public Instance Methods
find_by(val, attr = "id")
click to toggle source
used for hash of objects
# File lib/ext/hash.rb, line 21 def find_by(val, attr = "id") self.each do |key, p| if p[attr].to_s == val.to_s return p end end nil end
to_attr_format(split = " ")
click to toggle source
convert hash to string like class=“class val” name='name val'
# File lib/ext/hash.rb, line 3 def to_attr_format(split = " ") res = [] self.each do |key, value| res << "#{key} = \"#{value.to_s.gsub('"', '\"')}\"" end res.join(split) end
to_attr_url_format()
click to toggle source
convert hash to attributes for url_path
# File lib/ext/hash.rb, line 12 def to_attr_url_format res = [] self.each do |key, value| res << ":#{key} => \"#{value.to_s.gsub('"', '\"')}\"" end res.join "," end
to_sym()
click to toggle source
# File lib/ext/hash.rb, line 30 def to_sym symbolize(self) end
to_translate()
click to toggle source
Private Instance Methods
symbolize(obj)
click to toggle source
# File lib/ext/hash.rb, line 35 def symbolize(obj) return obj.inject({}){|memo,(k,v)| memo[k.to_sym] = symbolize(v); memo} if obj.is_a? Hash return obj.inject([]){|memo,v | memo << symbolize(v); memo} if obj.is_a? Array return obj end