Pluck for ActiveRecord on steroids
Installation
Add this line to your application's Gemfile:
gem 'pluckeroid'
And then execute:
$ bundle
Or install it yourself as:
$ gem install pluckeroid
Usage
Person.pluck(:id)
# => [1, 2]
Person.pluck_attributes(:id)
# => [{ 'id' => 1 }, { 'id' => 2 }]
Person.pluck(:id, :name)
# => [[1, 'Obi-Wan'], [2, 'Luke']]
Person.pluck_attributes(:id, :name)
# => [{ 'id' => 1, 'name' => 'Obi-Wan' }, { 'id' => 2, 'name' => 'Luke' }]
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Thanks
Based on native pluck
method and Ernie Miller's valium
project.