mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[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
1 changed files with 15 additions and 5 deletions
|
@ -166,11 +166,21 @@ class OpenStruct
|
||||||
# data.to_h {|name, value| [name.to_s, value.upcase] }
|
# data.to_h {|name, value| [name.to_s, value.upcase] }
|
||||||
# # => {"country" => "AUSTRALIA", "capital" => "CANBERRA" }
|
# # => {"country" => "AUSTRALIA", "capital" => "CANBERRA" }
|
||||||
#
|
#
|
||||||
def to_h(&block)
|
if {test: :to_h}.to_h{ [:works, true] }[:works] # RUBY_VERSION < 2.6 compatibility
|
||||||
if block
|
def to_h(&block)
|
||||||
@table.to_h(&block)
|
if block
|
||||||
else
|
@table.to_h(&block)
|
||||||
@table.dup
|
else
|
||||||
|
@table.dup
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
def to_h(&block)
|
||||||
|
if block
|
||||||
|
@table.map(&block).to_h
|
||||||
|
else
|
||||||
|
@table.dup
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue