diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/hashie/dash.rb | 7 | ||||
-rw-r--r-- | lib/hashie/extensions/dash/indifferent_access.rb | 9 |
2 files changed, 16 insertions, 0 deletions
diff --git a/lib/hashie/dash.rb b/lib/hashie/dash.rb index 785d94d..cfb151e 100644 --- a/lib/hashie/dash.rb +++ b/lib/hashie/dash.rb @@ -156,6 +156,13 @@ module Hashie self end + def to_h + defaults = ::Hash[self.class.properties.map { |prop| [prop, self.class.defaults[prop]] }] + + defaults.merge(self) + end + alias to_hash to_h + def update_attributes!(attributes) update_attributes(attributes) diff --git a/lib/hashie/extensions/dash/indifferent_access.rb b/lib/hashie/extensions/dash/indifferent_access.rb index 204cae6..50d4f93 100644 --- a/lib/hashie/extensions/dash/indifferent_access.rb +++ b/lib/hashie/extensions/dash/indifferent_access.rb @@ -19,6 +19,15 @@ module Hashie end private_class_method :requires_class_methods? + def to_h + defaults = ::Hash[self.class.properties.map do |prop| + [Hashie::Extensions::IndifferentAccess.convert_key(prop), self.class.defaults[prop]] + end] + + defaults.merge(self) + end + alias to_hash to_h + module ClassMethods # Check to see if the specified property has already been # defined. |