Question #1 :-
As per the documentation of Kernel#Hash
(Module: Kernel (Ruby 2.0.0))
- Returns an empty Hash when arg is nil or [].
RUBY_VERSION # => “2.0.0”
Hash[[“class”, “foo”]] # => {}
What happened with the below 2 cases :-
Hash[[[“class”, “foo”]]] # => {“class”=>“foo”}
Hash[nil] # => # ~> -:5:in `[]': odd number of arguments for Hash
(ArgumentError)
Question #2 :-
where is it documented?
kirti@kirti-Aspire-5733Z:~$ irb --simple-prompt
a = [“a” => 100, “b” => 200]
=> [{“a”=>100, “b”=>200}]
Hash[[“class”, “foo”]]
(irb):2: warning: wrong element type String at 0 (expected array)
(irb):2: warning: ignoring wrong elements is deprecated, remove them
explicitly
(irb):2: warning: this causes ArgumentError in the next release
(irb):2: warning: wrong element type String at 1 (expected array)
(irb):2: warning: ignoring wrong elements is deprecated, remove them
explicitly
(irb):2: warning: this causes ArgumentError in the next release
=> {}
Hash[*[“class”, “foo”]] #=> {“class”=>“foo”}
On Sat, Aug 24, 2013 at 9:59 AM, Love U Ruby [email protected]
wrote:
As per the documentation of Kernel#Hash
(Module: Kernel (Ruby 2.0.0))
- Returns an empty Hash when arg is nil or [].
RUBY_VERSION # => “2.0.0”
Hash[[“class”, “foo”]] # => {}
You are not invoking Kernel#Hash here but Hash#[].
robert
Robert K. wrote in post #1119503:
On Sat, Aug 24, 2013 at 9:59 AM, Love U Ruby [email protected]
wrote:
RUBY_VERSION # => “2.0.0”
Hash[[“class”, “foo”]] # => {}
You are not invoking Kernel#Hash here but Hash#[].
robert
@Robert - basically depending on what Kernel#Hash and Hash#[] methods
are switched between them?