Sha256: b7c9b5a0103238cf1fdd3086deb5941e543a1950e9e3d57e3934c1804d73536f

Contents?: true

Size: 1.19 KB

Versions: 17

Compression:

Stored size: 1.19 KB

Contents

require 'set'
require 'will_paginate/array'

# helper to check for method existance in ruby 1.8- and 1.9-compatible way
# because `methods`, `instance_methods` and others return strings in 1.8 and symbols in 1.9
#
#   ['foo', 'bar'].include_method?(:foo) # => true
class Array
  def include_method?(name)
    name = name.to_sym
    !!(find { |item| item.to_sym == name })
  end
end

unless Hash.instance_methods.include_method? :except
  Hash.class_eval do
    # Returns a new hash without the given keys.
    def except(*keys)
      rejected = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys)
      reject { |key,| rejected.include?(key) }
    end
 
    # Replaces the hash without only the given keys.
    def except!(*keys)
      replace(except(*keys))
    end
  end
end

unless Hash.instance_methods.include_method? :slice
  Hash.class_eval do
    # Returns a new hash with only the given keys.
    def slice(*keys)
      allowed = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys)
      reject { |key,| !allowed.include?(key) }
    end

    # Replaces the hash with only the given keys.
    def slice!(*keys)
      replace(slice(*keys))
    end
  end
end

Version data entries

17 entries across 17 versions & 12 rubygems

Version Path
will_paginate-2.3.17 lib/will_paginate/core_ext.rb
gigpark-will_paginate-2.3.11 lib/will_paginate/core_ext.rb
mislav-will_paginate-2.3.10 lib/will_paginate/core_ext.rb
shingara-will_paginate-2.3.10 lib/will_paginate/core_ext.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/will_paginate-2.3.16/lib/will_paginate/core_ext.rb
will_paginate-2.3.16 lib/will_paginate/core_ext.rb
tism-will_paginate-2.3.16 lib/will_paginate/core_ext.rb
Empact-will_paginate-2.3.15 lib/will_paginate/core_ext.rb
will_paginate-2.3.15 lib/will_paginate/core_ext.rb
will_paginate-2.3.14 lib/will_paginate/core_ext.rb
jkaneacumen-will_paginate-2.3.12 lib/will_paginate/core_ext.rb
djmaze-will_paginate-2.3.13 lib/will_paginate/core_ext.rb
larsklevan-will_paginate-2.3.12 lib/will_paginate/core_ext.rb
pb-will_paginate-2.3.12 lib/will_paginate/core_ext.rb
will_paginate-2.3.12 lib/will_paginate/core_ext.rb
leshill-will_paginate-2.3.11 lib/will_paginate/core_ext.rb
will_paginate-2.3.11 lib/will_paginate/core_ext.rb