summaryrefslogtreecommitdiff
path: root/lib/hashie/extensions/indifferent_access.rb
diff options
context:
space:
mode:
authorDaniel Doubrovkine (dB.) @dblockdotorg <dblock@dblock.org>2020-10-23 09:16:23 -0400
committerGitHub <noreply@github.com>2020-10-23 09:16:23 -0400
commitb741e5d7064fffd1ca4c5a6ca05b1ea6d87109ce (patch)
treefef8c25140223fbc9fc052f5c16a8091fdf551ae /lib/hashie/extensions/indifferent_access.rb
parent09581e249729cd7a962b4df47837247c79d4e7ea (diff)
parenta7d57c921dd9a3e99aff95bcae685f831cade7f9 (diff)
downloadhashie-b741e5d7064fffd1ca4c5a6ca05b1ea6d87109ce.tar.gz
Merge pull request #536 from michaelherold/export-normal-hash-from-indifferent
Allow exporting a normal, not-indifferent Hash
Diffstat (limited to 'lib/hashie/extensions/indifferent_access.rb')
-rw-r--r--lib/hashie/extensions/indifferent_access.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/hashie/extensions/indifferent_access.rb b/lib/hashie/extensions/indifferent_access.rb
index ebdb0f9..d6b9da3 100644
--- a/lib/hashie/extensions/indifferent_access.rb
+++ b/lib/hashie/extensions/indifferent_access.rb
@@ -143,6 +143,18 @@ module Hashie
super.convert!
end
+ def to_hash
+ {}.tap do |result|
+ each_pair { |key, value| result[key] = value }
+
+ if default_proc
+ result.default_proc = default_proc
+ else
+ result.default = default
+ end
+ end
+ end
+
with_minimum_ruby('2.5.0') do
def slice(*keys)
string_keys = keys.map { |key| convert_key(key) }