Module: Enumerable::Arguments

Module | Enumerable::Arguments
In: | lib/more/facets/enumargs.rb

### Methods

detect find to_a wrap_enumerable_method

### Public Class methods

wrap_enumerable_method( methodname )

[Source]

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

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

        case arity <=> 0
        when 0
          class_eval %{
            def #{m}( *args, &yld )
              enum_for(:each, *args).#{m}( &yld )
            end
          }
        when 1
          class_eval %{
            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 %{
            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)

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| ... }

[Source]

    # File lib/more/facets/enumargs.rb, line 91
      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

to_a(*args)

[Source]

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

[Validate]