I have a program that looks like:
$offset = Point.new(100, 200);
def draw(point)
pointNew = $offset + point;
drawAbsolute(point)
end
draw(Point.new(3, 4));
the use of $offset seems a bit weird. In C, if we define something outside of any function, it is a global variable automatically. I wonder why in Ruby, it has to be $offset but cannot be offset and still be global? If it is offset, then it is a local? But local to where? (because it feels very much global).
Are there better ways to write the code above? The use of $offset may seem a bit ugly at first. thanks.
Update: we can put this offset inside a class definition, but what if 2 or several classes need to use this constant? in this case do we still need to define an $offset?