Why Array#uniq doesn't take block? I think it's nice if we can pass
block.
I know it's enough when object is simple like Fixnum.
[1,2,2,3].uniq #=> [1,2,3]
but when it comes to complex object like ActiveRecord model
Company.all.uniq { |c| c.name }
I found a patch (Tickets - Ruby on Rails - rails
1595-patch-for-activesupport-that-arrayuniq-and-uniq-supports-blocks)
that enables this feature but it was rejected unfortunately.
Anyone have an idea why it's rejected?
>> Hi all.
>>
>> Why Array#uniq doesn't take block? I think it's nice if we can pass
>> block.
>> I know it's enough when object is simple like Fixnum.
>>
>> [1,2,2,3].uniq #=> [1,2,3]
>>
>> but when it comes to complex object like ActiveRecord model
>>
>> Company.all.uniq { |c| c.name }
>
> How would it know which record to keep and which to reject when it
> found two entries with the same name?
Or perhaps I misunderstand, perhaps you just mean
Company.all.map(&:name).uniq
Apart from the merits of the idiom itself, generally speaking Active
Support extends Ruby mostly to ease the development of Rails itself,
and only adds other core extensions when they are clearly of benefit
for almost any web application. That's the rule of thumb, it doesn't
mean you won't find a counterxample, but it's what guides additions.
In that sense Active Support has a different goal than Facets, for example.