# module Enumerable::Arguments

### Public Class Methods

wrap_enumerable_method( methodname ) click to toggle source

    # File lib/facets/enumargs.rb, line 50
    def self.wrap_enumerable_method( methodname )

      m = methodname
      meth = Enumerable.instance_method(m)
      arity = meth.arity

      case arity <=> 0
      when 0
        class_eval %Q{
          def #{m}( *args, &yld )
            enum_for(:each, *args).#{m}( &yld )
          end
        }
      when 1
        class_eval %Q{
          def #{m}( *args, &yld )
            args, each_args = args[0...#{arity}], args[#{arity}..-1]
            enum_for(:each, *each_args).#{m}( *args, &yld )
          end
        }
      else
        class_eval %Q{
          def #{m}( *args, &yld )
            enum_for(:each).#{m}( *args, &yld )
          end
        }
      end
    end

### Public Instance Methods

detect(*args, &yld)
Alias for: find
find(*args, &yld) click to toggle source

Make exception for find (a negative arity method) to accept keyword argument.

    ObjectSpace.find(Class, :ifnone=>lambda{1}) { |e| ... }
    ObjectSpace.find(Class, :ifnone=>lambda{1}) { |e| ... }

    # File lib/facets/enumargs.rb, line 94
    def find(*args, &yld)  # future use **keys ?
      if Hash === args.last and args.last.key?(:ifnone)
        ifnone = args.last.delete(:ifnone)
        args.pop if args.last.empty?
        enum_for(:each, *args).find( ifnone, &yld )
      else
        enum_for(:each, *args).find( &yld )
      end
    end

Also aliased as: detect
to_a(*args) click to toggle source

    # File lib/facets/enumargs.rb, line 84
    def to_a(*args)
      map(*args){ |x| x }
    end