I thought I’d weigh in here. Instead of relying on
per-variable syntax, what about a keyword? Here is
some fictional syntax.
class A
def foo
# regular instance variables @var = “hi”
# anything below 'local' here is a
# class-local instance variable
local:
var = "hello"
end
def bar
puts @var # ‘hi’
puts class.var # ‘hello’
end
end
Just an idea. Thoughts?
I’m not sure where “class.var” comes from… var is an instance
variable of A objects, it looks like, not of A (unless you meant that
local: clause to come after the method definition?) and in any case
you haven’t defined a method called ‘var’, just a variable.
Also, how would you differentiate between the instance variable var
and a local variable (or method) called var?
(Mind you, my basic feeling about ‘local’ is that I would dislike it Nonetheless I’m curious how you would see it playing out.)