I have a program that looks like this:
$offset = Point.new(100, 200); def draw(point) pointNew = $offset + point; drawAbsolute(point) end draw(Point.new(3, 4));
using $offset seems a bit odd.
In C, if I define something outside of any function, it is a global variable automatically. Why in Ruby should it be $offset , but cannot be offset and still global? If it is offset , is it local? But locally, where, because it feels very global.
Are there any better ways to write the code above? Using $offset may seem a little ugly at first.
Update: I can put this offset inside the class definition, but what if two or more classes have to use this constant? In this case, do I still need to determine $offset ?
ruby global-variables
nopole Jun 25 '09 at 6:03 2009-06-25 06:03
source share