Q1: Why does Ruby somehow create an array for lines 1 & 2?
Q2: Why does Ruby assign this array to a, but the scalar (20) to b?
Q3: If Ruby’s willing to build arrays for lines 1 & 2, why won’t it
build a hash for line 3?
The assignment of 20 to b happens first, and then the whole rhs is
assigned to a. From a’s point of view, this is the same as:
a = 10,20
and assigning a literal list like that works like assigning an array.
As for the third line: x => 1000 isn’t a legal expression on its own.
=> is not an assignment operator; it’s just a hash key/value
separator.
David
–
Q. What’s a good holiday present for the serious Rails developer?
A. RUBY FOR RAILS by David A. Black (Ruby for Rails)
aka The Ruby book for Rails developers!
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)
Thanks for your clarification. Now that you explain (a=10, b=20), my
brain said: You read that before, Dummy … why do you always forget
things?
I had just found a nice tutorial on sorting tables by clicking on
column headings. It included a long line of comma-separated
assignments and I couldn’t make sense of it. Now I’m grounded again!
Again, thanks.
Best wishes,
Richard
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.