I'm find the the whole method_missing, privative clashing methods,
except essential ones, call send otherwise . . . is just a pain. The
whole thing is just to have that nice interface "obj.foo, obj.foo=x".
That might not seem like much but it really stand out in contrast:
obj[:a][:b][:c] -vs- obj.a.b.c
So, dang, if that's all we want, some beauty in our code, and the whole
method_missing thing is just too problematic why not just have another
means? Anuone having a look at Hpricot recently will note the
x/:a/:b/:c notation. No bad, that almost as nice. Okay, step back ...
I was thinking... soon we will become acustom to space significance
with the new Hash notation
{ x: :a } != { x::a }
If we're gogin to be dealing with space significance here anyway, why
not go with it give us the ability to reusue ':'?
class X < Hash
# parameter is always a symbol
def :(x)
self[x]
end
def :=(x,y)
self[x] = y
end
def x(n)
n
end
end
x = X
x:y = 4
x:y #=> 4
x(:y) #=> :y
x :y #=> :y
So then we can easily do
obj:a:b:c
That's just about as nice. Of course the disadvantage is that it's not
very ducky --if you take my meaning. Of course, thinking about that,
one might be inclined to ask, why not just have a special Dispatcher
superclass?
class MyClass < Dispatcher
# only two methods allowed
def .(x, *args, &blk)
...
end
def .=(x,y)
...
end
end
If only .... then I wouldn't be in so deep. Someone save me!
T.