aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2012-03-29 16:25:50 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2012-03-29 16:25:50 -0700
commit648248bbb13aa5259b1e64d9a8376cdbe6717e37 (patch)
treeefcba839bfb8e20b61df08abb95c851e68318925 /activerecord/lib/active_record
parent1555023973d2f60050f16b055335abc4e038e20f (diff)
parentbb2e2d8cb6fda1a093925fb6f79ef44f404bf785 (diff)
downloadrails-648248bbb13aa5259b1e64d9a8376cdbe6717e37.tar.gz
rails-648248bbb13aa5259b1e64d9a8376cdbe6717e37.tar.bz2
rails-648248bbb13aa5259b1e64d9a8376cdbe6717e37.zip
Merge pull request #5345 from guilleiguaran/ar-slice
post.slice(:title, :content) # => { title: "Hello", content: "World" }
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/core.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb
index 9a2f859fc7..76c424e8b4 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -1,4 +1,5 @@
require 'active_support/concern'
+require 'active_support/core_ext/hash/indifferent_access'
require 'thread'
module ActiveRecord
@@ -326,6 +327,11 @@ module ActiveRecord
"#<#{self.class} #{inspection}>"
end
+ # Returns a hash of the given methods with their names as keys and returned values as values.
+ def slice(*methods)
+ Hash[methods.map { |method| [method, public_send(method)] }].with_indifferent_access
+ end
+
private
# Under Ruby 1.9, Array#flatten will call #to_ary (recursively) on each of the elements