# File lib/standard/facets/enumargs.rb, line 34 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 # this branch is used when the method has a variable number of arguments # resulting in an arity of -1. Right now this is bugged as it does # not pass the argument to the each, and always passes the argument # to the method. This makes methods like .min amdn .max to act # in an unexpected manner. class_eval %{ def #{m}( *args, &yld ) enum_for(:each).#{m}( *args, &yld ) end } end end