[ruby/ostruct] Add compatibility for to_h with block in Ruby 2.5
https://github.com/ruby/ostruct/commit/da45de5068
This commit is contained in:
parent
37b445eaeb
commit
7f1323c3bd
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user