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

Version Path
rad_core-0.2.6 lib/rad/_support/hacks_and_fixes.rb
rad_core-0.2.5 lib/rad/_support/hacks_and_fixes.rb
rad_core-0.2.4 lib/rad/_support/hacks_and_fixes.rb
rad_core-0.2.3 lib/rad/_support/hacks_and_fixes.rb
rad_core-0.2.2 lib/rad/_support/hacks_and_fixes.rb
rad_core-0.2.1 lib/rad/_support/hacks_and_fixes.rb
rad_core-0.2.0 lib/rad/_support/hacks_and_fixes.rb
rad_core-0.0.30 lib/rad/_support/hacks_and_fixes.rb
rad_core-0.0.29 lib/rad/_support/hacks_and_fixes.rb
rad_core-0.0.28 lib/rad/_support/hacks_and_fixes.rb
rad_core-0.0.27 lib/rad/_support/hacks_and_fixes.rb
rad_core-0.0.26 lib/rad/_support/hacks_and_fixes.rb
rad_core-0.0.25 lib/rad/_support/hacks_and_fixes.rb
rad_core-0.0.24 lib/rad/_support/hacks_and_fixes.rb
rad_core-0.0.23 lib/rad/_support/hacks_and_fixes.rb
rad_core-0.0.22 lib/rad/_support/hacks_and_fixes.rb
rad_core-0.0.21 lib/rad/_support/hacks_and_fixes.rb
rad_core-0.0.20 lib/rad/_support/hacks_and_fixes.rb
rad_core-0.0.19 lib/rad/_support/hacks_and_fixes.rb
rad_core-0.0.18 lib/rad/_support/hacks_and_fixes.rb