Sha256: 37cf06d723f477853d5988f8e07d55aa2d2d23a72d58882d5c817ccbc2d18688
Contents?: true
Size: 1017 Bytes
Versions: 23
Compression:
Stored size: 1017 Bytes
Contents
# # Problem: the Hash::slice method in ActiveSupport works a little differently than in Facets. # And because Facets is overrides ActiveSupport version this causes problems (for example in to_json method) # In ActiveSupport it returns :nil if there's no key in Facets it raises error. # # Use Case: # hash = {:items=>[], "slug"=>"item-z8w", "name"=>"Item", "created_at"=>"2011-01-10T07:04:01Z", "dependent"=>"false", "viewers"=>["manager", "user:user1"], "updated_at"=>"2011-01-10T07:04:01Z", :icon_url=>"null", "text"=>"null", "tags"=>[], "owner_name"=>"user1", "_type"=>"Selector"} # args = ["id", "_type", "slug", "name", "text", "tags", "dependent", "owner_name", "viewers", "created_at", "updated_at"] # hash.slice *args # # Solution: # Redefining :slice the same way as in ActiveSupport. # # TODO1 remove it, we don't use facets anymore class Hash def slice(*keep_keys) hash = {} keep_keys.each do |key| # hash[key] = fetch(key) hash[key] = self[key] end hash end end
Version data entries
23 entries across 23 versions & 1 rubygems