Robot Has No Heart

Xavier Shay blogs here

A robot that does not have a heart

This is stupid: Hash#select vs reject

A little consistency would be nice…

1
2
{1=>1, 2=>2, 3=>3}.reject {|key, value| key != 1 } # => {1=>1}
{1=>1, 2=>2, 3=>3}.select {|key, value| key == 1 } # => [[1, 1]]
  1. Matthew Delves says:

    I’m most likely missing something, but how is this inconsistent?

  2. Xavier Shay says:

    reject/select are the converse of each other, they should have the same return type. I think hash is correct, I have seen arguments that array would be the correct type. Either way, they should be the same.

Post a comment


(lesstile enabled - surround code blocks with ---)

A pretty flower Another pretty flower