I have a Ruby object that looks like this:
- !ruby/object:Foo
attributes:
updated: 2013-07-30 13:30:21.589221000 Z
bar: 3
- !ruby/object:Statistic
attributes:
updated: 2013-07-30 13:30:28.017951000 Z
bar: 8
- !ruby/object:Statistic
attributes:
updated: 2013-07-30 13:30:39.514180000 Z
bar: 1
The object comes from an ActiveRecord query.
I would like to get an array of all the bars in this object i.e.
[3, 8, 1]
Is there some slick way of doing this in Ruby?
If you only want one attribute from an ActiveRecord query, you can use pluck:
Foo.all.pluck(:bar)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With