diff options
author | Michael Herold <opensource@michaeljherold.com> | 2020-10-29 19:49:08 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-29 19:49:08 -0500 |
commit | 75410a6657090348de7bff3e5eab8aa684e49c38 (patch) | |
tree | 27e0eab23a209706b738bcfcf5736220fc3ac871 /lib/hashie/dash.rb | |
parent | 59d04c851e8ae80d82e93d82059e591eaa7718a7 (diff) | |
parent | f152e25912d0b93ff08b8964eb757200ad4b6f32 (diff) | |
download | hashie-75410a6657090348de7bff3e5eab8aa684e49c38.tar.gz |
Merge pull request #537 from michaelherold/dash-consistency
Fix inconsistencies with Dash defaults
Diffstat (limited to 'lib/hashie/dash.rb')
-rw-r--r-- | lib/hashie/dash.rb | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/lib/hashie/dash.rb b/lib/hashie/dash.rb index 460790b..785d94d 100644 --- a/lib/hashie/dash.rb +++ b/lib/hashie/dash.rb @@ -104,19 +104,6 @@ module Hashie def initialize(attributes = {}, &block) super(&block) - self.class.defaults.each_pair do |prop, value| - self[prop] = begin - val = value.dup - if val.is_a?(Proc) - val.arity == 1 ? val.call(self) : val.call - else - val - end - rescue TypeError - value - end - end - initialize_attributes(attributes) assert_required_attributes_set! end @@ -173,13 +160,19 @@ module Hashie update_attributes(attributes) self.class.defaults.each_pair do |prop, value| - next unless self[prop].nil? + next unless fetch(prop, nil).nil? self[prop] = begin - value.dup + val = value.dup + if val.is_a?(Proc) + val.arity == 1 ? val.call(self) : val.call + else + val + end rescue TypeError value end end + assert_required_attributes_set! end @@ -189,7 +182,7 @@ module Hashie return unless attributes cleaned_attributes = attributes.reject { |_attr, value| value.nil? } - update_attributes(cleaned_attributes) + update_attributes!(cleaned_attributes) end def update_attributes(attributes) |