This project is archived and is in readonly mode.

#1595 ✓wontfix
Artūras Šlajus

Patch for ActiveSupport that Array#uniq and #uniq! supports blocks

Reported by Artūras Šlajus | December 18th, 2008 @ 02:17 PM | in 2.x

I found it useful when i wanted to ensure that array has no duplicate values while somehow transforming them, but not affecting original array so I wrote a patch that provides uniq and uniq! block support

# Same as Array#uniq but accepts block argument which result will 
# be used for determining which values are unique.
#   a = ['a', 'A', 'bb', 'bB', 'Bb', 'Cc', 'cc']
#   a.uniq { |i| i.downcase } # => ["a", "bb", "Cc"]

Github commit:

The append features part is lame, I think it should be rewritten somehow :)

Comments and changes to this ticket

  • Dmitry Polushkin

    Dmitry Polushkin December 19th, 2008 @ 11:20 AM

    Overheat, it could be done using:

  • Artūras Šlajus

    Artūras Šlajus December 19th, 2008 @ 11:51 AM

    But doing so destroys original values.

    For example my patch is very useful for tagging support where we want to keep original values.

    >> a = ["Drum and bass", "drum'and'bass"]
    => ["Drum and bass", "drum'and'bass"]
    >> { |i| i.parameterize.to_s }.uniq
    => ["drum-and-bass"]
    >> a.uniq { |i| i.parameterize.to_s }
    => ["Drum and bass"]
  • Pratik

    Pratik December 19th, 2008 @ 01:46 PM

    • State changed from “new” to “wontfix”

    I don't think this belongs in core.


  • Artūras Šlajus

    Artūras Šlajus December 19th, 2008 @ 11:06 PM

    And why does other stuff in activesupport belong in core? Not that I like being itchy but this patch doesn't hurt and perhaps it will be useful for someone?

    What's the motivation of dropping it out?

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket