rubyworks / facets

Ruby Facets

Home Page:http://rubyworks.github.com/facets

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hash#except .. in Enumerable?

jtzero opened this issue · comments

this might sound naive, but why isn't Hash#except in Enumerable, such that

  # @param  *less_objs
  # @return [Enumerable]
  def except(*less_objs)
    reject {|item| less_objs.include?(item) }
  end

it would work with Array [1,2,3,4].except(3) => [1,2,4]
and hash still {:me => 'arg', :pirate => 'yarg'}.except(:me) => {:pirate => 'yarg'}

Hmm... my only reservation is that Hash#except deals with the keys. Polymorphically, Hash keys correlate to Array indexes. So [1,2,3,4].except(3) => [1,2,3]. But I see how a value-oriented "except" would be useful for Array, and Hash too. Essentially it is #reject but one that takes arguments rather then a block.... I think we have that in #delete and #delete_values.

Yet... #delete acts in place. So we don't have a non-in-place form of delete. So maybe we add something like #remove for that?

Also, I forgot to say, it would therefore seem that an Array#expect that acted on the index would be a consistent addition.

"Also, I forgot to say, it would therefore seem that an Array#expect that acted on the index would be a consistent addition" -> I think that would be better served as Array#except_at, more like Array#delete_at