I'm writing a piece of AI code as a means to learn Ruby. I'm getting confused on some syntactical choices that don't seem to make a differece (yet.)
So here are a flurry of questions:
-When defining a global variable; do you use the '@' sign? Why or why not? I.E. somevar vs. @somevar
It seems I don't need to, but it feels
wrong to have variables that have different symbols in front of them
-When defining class variables; do you use '@', '@@', or just the name? Why? It seems '@' is the appropriate way to go but various websites show people do it different ways.
-Would this be the proper way to copy identity's value into a variable? Again, it seems to work in the code but it may be inefficient, deprecated syntax or something else.
Code:
class Piece
def initialize
@value=0
def value
@value
end
end
p = piece.new.value
Thank you for helping a newb on a crash course
