Permalink
Browse files

Use private method for setting defaults

  • Loading branch information...
1 parent 6c893a8 commit 74c47e247b9bee9cc00758cc64a4f20fc9e0653e Markus Schirp committed Jul 20, 2012
Showing with 12 additions and 5 deletions.
  1. +12 −5 lib/virtus/instance_methods.rb
@@ -153,12 +153,8 @@ def to_hash
# user.frozen? # => true
#
# @api public
- #
def freeze
- # Call get_attribute on all attribute to ensure defaults are set prior to freezing
- attribute_set.each do |attribute|
- get_attribute(attribute.name)
- end
+ set_defaults
super
end
@@ -176,6 +172,17 @@ def get_attributes
end
end
+ # Ensure all defaults are set
+ #
+ # @return [AttributeSet]
+ #
+ # @api private
+ def set_defaults
+ attribute_set.each do |attribute|
+ get_attribute(attribute.name)
+ end
+ end
+
# Mass-assign attribute values
#
# @see Virtus::InstanceMethods#attributes=

0 comments on commit 74c47e2

Please sign in to comment.