# Do a set of records have the same value for one of the fields?

**URL:** <https://www.ruby-forum.com/t/do-a-set-of-records-have-the-same-value-for-one-of-the-fields/174495>\
**Category:** Rails\
**Created:** [August 27, 2009, 4:17pm UTC](https://www.ruby-forum.com/t/do-a-set-of-records-have-the-same-value-for-one-of-the-fields/174495 "2009-08-27T16:17:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![oldbug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c0e974/32.png) [@oldbug](https://www.ruby-forum.com/u/oldbug)\
**Post date:** [August 27, 2009, 4:17pm UTC](https://www.ruby-forum.com/t/do-a-set-of-records-have-the-same-value-for-one-of-the-fields/174495/1 "2009-08-27T16:17:25Z")

</div>

Hi Folks,  
I’m looking for an elegant Ruby one-liner…

I have a set of records in my database that I want to check to see if  
the :description field is identical.

And, because it’s Thursday morning (where I live), I would like to do  
it as elegantly and as one-line-er-ly as I can

Something like…

records.map(&:description).all?(&:==)

which, doesn’t work

I’ll go ahead and split it into a couple of lines, and make sure that  
all of the descriptions match record[0].descriptions, but I am certain  
there is a more elegant solution than this.

–wpd

---

<div class="post-metadata">

**Author:** ![oldbug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c0e974/32.png) [@oldbug](https://www.ruby-forum.com/u/oldbug)\
**Post date:** [August 27, 2009, 4:36pm UTC](https://www.ruby-forum.com/t/do-a-set-of-records-have-the-same-value-for-one-of-the-fields/174495/2 "2009-08-27T16:36:09Z")

</div>

On 27 Aug 2009, at 15:09, Patrick D. wrote:

> Something like…
> 
> records.map(&:description).all?(&:==)

Well if you’re desperate for a one-liner  
records.map(&:description).uniq.length == 1

Fred

---

<div class="post-metadata">

**Author:** ![oldbug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c0e974/32.png) [@oldbug](https://www.ruby-forum.com/u/oldbug)\
**Post date:** [August 27, 2009, 11:07pm UTC](https://www.ruby-forum.com/t/do-a-set-of-records-have-the-same-value-for-one-of-the-fields/174495/3 "2009-08-27T23:07:47Z")

</div>

> > records.map(&:description).all?(&:==)

nice… I was trying to figure out something with #inject/#sum, but  
that looks great.

–wpd
