If local_variable == @variable
-
My SU page fonts are huge today,-), my eyes are not that bad, yet. Anyway I notice that I can not test different kinds of variables, as the following fails:
def anything something if local_variable == @variable something else something else end end
While the following works:
def anything something if @local_variable == @variable something else something else end end
Is it a rule in Ruby that you can not test different kinds of variables? Is there other things I need to be aware of because of this?
-
@honoluludesktop said:
My SU page fonts are huge today,-)
SCF you mean? At the top of the page, upper right, you can swap between sizes.
@honoluludesktop said:
Anyway I notice that I can not test different kinds of variables, as the following fails:
Fails with error message, or just doesn't do what you want?
There should be no restrictions, but are you sure you defined all the variables?
-
Yeah, at the office, I get to adjust the view zoom font %, so I found that I had to scale down from 125% to 100%. Don't know why the machine woke up at 125%.
Don't recall error massage, but I didn't separately declare the local variable (vari_1 = 0, vari_2 = 0). OK, I thought that local variables could be created on the fly. Sigh...
-
@honoluludesktop said:
variables could be created on the fly. Sigh...
` x=3
3
puts 'hello' if y == x
Error: #<NameError: undefined local variable or methody' for main:Object> (eval):15
when comparing you need to have initialized the variable.
-
Note that instance variables doesn't act the same:
puts 'hello' if @y == x nil
-
OK, thanks.
-
@honoluludesktop said:
My SU page fonts are huge today,-), my eyes are not that bad, yet. Anyway I notice that I can not test different kinds of variables, as the following fails:
def anything > something > if local_variable == @variable > something > else > something else > end > end
While the following works:
def anything > something > if @local_variable == @variable > something > else > something else > end > end
Is it a rule in Ruby that you can not test different kinds of variables? Is there other things I need to be aware of because of this?
you need to initialize the local variables. Otherwise you get an error.
Instance variables (with
@
) are initialized tonil
by default, and this is why you don't get an error.Fredo
-
And class variables
@@
.
Advertisement