diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-08-21 00:50:42 -0300 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-08-21 00:50:43 -0300 |
commit | 15e2b80a27c7fd48f1a3e22d1682281515b2c371 (patch) | |
tree | 0e7efe1923500601e1805a3b4d8c5a8a948b10f7 /activerecord | |
parent | e7ffa779322fcd864afe2b94c6fceaa3181535fb (diff) | |
download | rails-15e2b80a27c7fd48f1a3e22d1682281515b2c371.tar.gz rails-15e2b80a27c7fd48f1a3e22d1682281515b2c371.tar.bz2 rails-15e2b80a27c7fd48f1a3e22d1682281515b2c371.zip |
Minor refactoring in Active Record model schema methods
* Use each_key instead of generating intermediate keys array.
* Use each_with_object instead of inject to build hash.
* Use ternary to return instead of if + assignment.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/model_schema.rb | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb index ff7c996648..99de16cd33 100644 --- a/activerecord/lib/active_record/model_schema.rb +++ b/activerecord/lib/active_record/model_schema.rb @@ -225,7 +225,7 @@ module ActiveRecord def decorate_columns(columns_hash) # :nodoc: return if columns_hash.empty? - serialized_attributes.keys.each do |key| + serialized_attributes.each_key do |key| columns_hash[key] = AttributeMethods::Serialization::Type.new(columns_hash[key]) end @@ -259,13 +259,12 @@ module ActiveRecord # and true as the value. This makes it possible to do O(1) lookups in respond_to? to check if a given method for attribute # is available. def column_methods_hash #:nodoc: - @dynamic_methods_hash ||= column_names.inject(Hash.new(false)) do |methods, attr| + @dynamic_methods_hash ||= column_names.each_with_object(Hash.new(false)) do |attr, methods| attr_name = attr.to_s methods[attr.to_sym] = attr_name methods["#{attr}=".to_sym] = attr_name methods["#{attr}?".to_sym] = attr_name methods["#{attr}_before_type_cast".to_sym] = attr_name - methods end end @@ -324,8 +323,7 @@ module ActiveRecord # Guesses the table name, but does not decorate it with prefix and suffix information. def undecorated_table_name(class_name = base_class.name) table_name = class_name.to_s.demodulize.underscore - table_name = table_name.pluralize if pluralize_table_names - table_name + pluralize_table_names ? table_name.pluralize : table_name end # Computes and returns a table name according to default conventions. |