summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/ostruct.rb20
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index 581dd73ea7..1462901d06 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -166,11 +166,21 @@ class OpenStruct
# data.to_h {|name, value| [name.to_s, value.upcase] }
# # => {"country" => "AUSTRALIA", "capital" => "CANBERRA" }
#
- def to_h(&block)
- if block
- @table.to_h(&block)
- else
- @table.dup
+ if {test: :to_h}.to_h{ [:works, true] }[:works] # RUBY_VERSION < 2.6 compatibility
+ def to_h(&block)
+ if block
+ @table.to_h(&block)
+ else
+ @table.dup
+ end
+ end
+ else
+ def to_h(&block)
+ if block
+ @table.map(&block).to_h
+ else
+ @table.dup
+ end
end
end