diff options
Diffstat (limited to 'activemodel/lib')
-rw-r--r-- | activemodel/lib/active_model/dirty.rb | 2 | ||||
-rw-r--r-- | activemodel/lib/active_model/serialization.rb | 11 | ||||
-rw-r--r-- | activemodel/lib/active_model/serializers/xml.rb | 7 | ||||
-rw-r--r-- | activemodel/lib/active_model/validations/acceptance.rb | 2 |
4 files changed, 6 insertions, 16 deletions
diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb index 1361d327b3..1dfd0b6132 100644 --- a/activemodel/lib/active_model/dirty.rb +++ b/activemodel/lib/active_model/dirty.rb @@ -115,7 +115,7 @@ module ActiveModel # person.name = 'bob' # person.changes # => { 'name' => ['bill', 'bob'] } def changes - changed.inject(HashWithIndifferentAccess.new){ |h, attr| h[attr] = attribute_change(attr); h } + HashWithIndifferentAccess[changed.map { |attr| [attr, attribute_change(attr)] }] end # Map of attributes that were changed when the model was saved. diff --git a/activemodel/lib/active_model/serialization.rb b/activemodel/lib/active_model/serialization.rb index 8f90ef64ba..37739b98a1 100644 --- a/activemodel/lib/active_model/serialization.rb +++ b/activemodel/lib/active_model/serialization.rb @@ -79,15 +79,8 @@ module ActiveModel attribute_names -= except end - method_names = Array.wrap(options[:methods]).inject([]) do |methods, name| - methods << name if respond_to?(name.to_s) - methods - end - - (attribute_names + method_names).inject({}) { |hash, name| - hash[name] = send(name) - hash - } + method_names = Array.wrap(options[:methods]).map { |n| n if respond_to?(n.to_s) }.compact + Hash[(attribute_names + method_names).map { |n| [n, send(n)] }] end end end diff --git a/activemodel/lib/active_model/serializers/xml.rb b/activemodel/lib/active_model/serializers/xml.rb index e89385e7e5..26a134568c 100644 --- a/activemodel/lib/active_model/serializers/xml.rb +++ b/activemodel/lib/active_model/serializers/xml.rb @@ -76,10 +76,9 @@ module ActiveModel end def serializable_methods - Array.wrap(options[:methods]).inject([]) do |methods, name| - methods << self.class::MethodAttribute.new(name.to_s, @serializable) if @serializable.respond_to?(name.to_s) - methods - end + Array.wrap(options[:methods]).map do |name| + self.class::MethodAttribute.new(name.to_s, @serializable) if @serializable.respond_to?(name.to_s) + end.compact end def serialize diff --git a/activemodel/lib/active_model/validations/acceptance.rb b/activemodel/lib/active_model/validations/acceptance.rb index d9dfe0c855..a7296d8e1d 100644 --- a/activemodel/lib/active_model/validations/acceptance.rb +++ b/activemodel/lib/active_model/validations/acceptance.rb @@ -14,8 +14,6 @@ module ActiveModel end def setup(klass) - # Note: instance_methods.map(&:to_s) is important for 1.9 compatibility - # as instance_methods returns symbols unlike 1.8 which returns strings. attr_readers = attributes.reject { |name| klass.attribute_method?(name) } attr_writers = attributes.reject { |name| klass.attribute_method?("#{name}=") } klass.send(:attr_reader, *attr_readers) |