From 01ede9a211d91d415488d42ff8015809de2ac497 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sat, 10 Mar 2012 19:39:13 -0500 Subject: Add ActiveRecord::Base#slice to slice method calls --- activerecord/lib/active_record/core.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'activerecord/lib/active_record/core.rb') 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 -- cgit v1.2.3