Sha256: 4da553bd285b7935de86848f2520a0e637eef8bfb2567a077c6bd95a8e907e61

Contents?: true

Size: 1.19 KB

Versions: 14

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

14 entries across 14 versions & 1 rubygems

Version Path
refinerycms-0.9.6.34 vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb
refinerycms-0.9.6.33 vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb
refinerycms-0.9.6.32 vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb
refinerycms-0.9.6.31 vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb
refinerycms-0.9.6.30 vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb
refinerycms-0.9.6.29 vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb
refinerycms-0.9.6.28 vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb
refinerycms-0.9.6.27 vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb
refinerycms-0.9.6.26 vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb
refinerycms-0.9.6.25 vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb
refinerycms-0.9.6.24 vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb
refinerycms-0.9.6.23 vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb
refinerycms-0.9.6.22 vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb
refinerycms-0.9.6.21 vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb