So I'm new to Prolog and Ruby. Studying Prolog at University and Ruby on my own. And I thought, if in Ruby there is a variable "not caring" or "discard", as it is in Prolog.
I just opened irb and just did it (suppose the underscore was a “don't care” sign)
1.9.2-p290 :003 > _, b, c = [1,2,3] => [1, 2, 3] 1.9.2-p290 :004 > b => 2 1.9.2-p290 :005 > c => 3
The results I actually expected. But then I was curious where, where is the meaning of the underline and what class was it
1.9.2-p290 :006 > _ => 3 1.9.2-p290 :008 > _.class => Fixnum
Well, that is weird. Shouldn't this drop value? Why is a different value stored?
Then, doing more underscore tests, I saw what really happened, it has the last evaluated value.
1.9.2-p290 :017 > 1 => 1 1.9.2-p290 :018 > _ => 1 1.9.2-p290 :019 > "string" => "string" 1.9.2-p290 :020 > _ => "string" 1.9.2-p290 :021 > Hash => Hash 1.9.2-p290 :022 > _ => Hash
So my question is: what exactly should I emphasize? Is it really not important, a variable or something else? What is the real name for him? (because I don’t find many things with a “ruby variable not important” with google)
source share