Sha256: 083ef25e2f3744d1d30ab62a69de13545d8050a7c23839f09f26aded7bc2f36d
Contents?: true
Size: 968 Bytes
Versions: 2
Compression:
Stored size: 968 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. # 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rad_core-0.0.14 | lib/rad/_support/hacks_and_fixes.rb |
rad_core-0.0.13 | lib/rad/support/hacks_and_fixes.rb |