Skip to content

Commit 1486999

Browse files
authored
Merge pull request #101 from k-tsuchiya-jp/fix-100
Explicitly define `:_default_attribute_values` using `class_attribute` in child class
2 parents 2196b23 + ab9ccba commit 1486999

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

lib/default_value_for.rb

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,18 @@ def default_value_for(attribute, options = {}, &block)
6565
allows_nil = opts.fetch('allows_nil', true)
6666
end
6767

68-
if !method_defined?(:set_default_values)
68+
if !singleton_methods(false).include?(:_default_attribute_values)
6969
include(InstanceMethods)
7070

7171
after_initialize :set_default_values
7272

7373
class_attribute :_default_attribute_values
7474
class_attribute :_default_attribute_values_not_allowing_nil
7575

76-
extend(DelayedClassMethods)
77-
init_hash = true
78-
else
79-
init_hash = !singleton_methods(false).include?(:_default_attribute_values)
80-
end
81-
82-
if init_hash
8376
self._default_attribute_values = {}
8477
self._default_attribute_values_not_allowing_nil = []
78+
79+
extend(DelayedClassMethods)
8580
end
8681

8782
if block_given?

0 commit comments

Comments
 (0)