7stud2
(7stud --)
24 August 2013 07:59
1
As per the documentation of `Kernel#Hash`
(http://www.ruby-doc.org/core-2.0/Kernel.html#method-i-Hash )
- Returns an empty Hash when arg is nil or [].
RUBY_VERSION # => "2.0.0"
Hash[["class", "foo"]] # => {}
What happened with the below 2 cases :-
- why not empty hash `{}` ?
Hash[[["class", "foo"]]] # => {"class"=>"foo"}
- why the error ?
Hash[nil] # => # ~> -:5:in `[]': odd number of arguments for Hash
(ArgumentError)
···
--
Posted via http://www.ruby-forum.com/ .
7stud2
(7stud --)
24 August 2013 10:20
2
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"}
···
--
Posted via http://www.ruby-forum.com/ .
You are not invoking Kernel#Hash here but Hash# .
robert
···
On Sat, Aug 24, 2013 at 9:59 AM, Love U Ruby <lists@ruby-forum.com> 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"]] # => {}
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
7stud2
(7stud --)
24 August 2013 17:13
4
Robert Klemme wrote in post #1119503:
···
On Sat, Aug 24, 2013 at 9:59 AM, Love U Ruby <lists@ruby-forum.com> > 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?
--
Posted via http://www.ruby-forum.com/\ .