Issue #6150 has been updated by Eregon (Benoit Daloze).


Suraj wrote:
> it's uncommon for Ruby core API to accept options hash. [...]
> Precedents can be found throughout the FileUtils standard library: [...]

You'll note most of these methods accept an options Hash (e.g.: rm_rf = rm_r list, options.merge(:force => true)).

Also, to add to what Thomas Sawyer said, FileUtils is a CLI(command)-like API, which Enumerable is definitely not (although likely inspired for the "grep" name).

Rodrigo Rosenfeld Rosas wrote:
> Of course, after Ruby support named parameters this could be acceptable too and I would always use it by passing the named parameter instead of just "true".

Be aware that keyword arguments as implemented now (if that is what you mean) do not permit this, they just allow an easier syntax to handle arguments and some optimization:

    module Enumerable
      def grep(matcher, invert: false)
        if invert
          reject { |e| matcher === e }
        else
          select { |e| matcher === e }
        end
      end
    end

    %w[1 2 11 22].grep(/1/) # => ["1", "11"]
    %w[1 2 11 22].grep(/1/, invert: true) # => ["2", "22"]
----------------------------------------
Feature #6150: add Enumerable#grep_v
https://bugs.ruby-lang.org/issues/6150#change-25357

Author: sunaku (Suraj Kurapati)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


Please add a grep_v() method to Enumerable that behaves like the opposite of grep().

For example, if Enumerable#grep() was implemented like this:

module Enumerable
  def grep pattern
    select {|x| pattern =~ x }
  end
end

then Enumerable#grep_v() would be implemented like this (select becomes reject):

module Enumerable
  def grep_v pattern
    reject {|x| pattern =~ x }
  end
end


The method name "grep_v" comes from the "-v" option passed to grep(1).

Thanks for your consideration.


-- 
http://bugs.ruby-lang.org/