gabriele renzi wrote:
"p" may stand for self#p, or a local variable named "p".
This case can be resolved fairly easily. (If there's an assignment to p
then it is a variable)
Yes, and if there is a variable named "foo" in
foo arg1
then it is calling that one instead of the old 'foo' method.
However think about this case:
def foo
puts 0
lambda { puts 1; lambda { puts 2; lambda { puts 3 }}}
end
foo # What will this do?
0 #=> #<Proc>
foo() # What will this do?
0 #=> #<Proc>
x = foo; x # What will this do?
0 #=> #<Proc>
x = foo; x() # What will this do?
01 #=> #<Proc2>
x = foo(); x # What will this do?
0 #=> #<Proc>
x = foo(); x() # What will this do?
01 #=> #<Proc2>
x = foo; y = x; y # What will this do?
0 #=> #<Proc>
x = foo(); y = x; y # What will this do?
0 #=> #<Proc>
x = foo(); y = x(); y # What will this do?
01 #=> #<Proc2>
x = foo; y = x(); y # What will this do?
01 #=> #<Proc2>
x = foo; y = x(); y() # What will this do?
012 #=> #<Proc3>
x = foo; y = x; y() # What will this do?
01 #=> #<Proc2>
x = foo(); y = x(); y # What will this do?
01 #=> #<Proc2>
x = foo(); y = x(); y() # What will this do?
012 #=> #<Proc3>
Etc. -- there are many cases here.
yes, but the rule is quite simple
Note that I may have 'computed' the things myself and I may be wrong.
Anyway, sample implementation:
B=binding
=> #<Binding:0x28ba600>
def method_missing(s,*a,&b)
eval(s.to_s,B).call *a, &b
end
=> nil
def foo
puts 0
lambda { puts 1; lambda { puts 2; lambda { puts 3 }}}
end
=> nil
foo
0
=> #<Proc:0x028a43a0@(irb):7>
foo()
0
=> #<Proc:0x028a43a0@(irb):7>
x=foo(); x
=> #<Proc:0x028a43a0@(irb):7>
x=foo(); x()
0
1
=> #<Proc:0x028a4538@(irb):7>
x=foo; x()
0
1
=> #<Proc:0x028a4538@(irb):7>
x=foo; y=x; y
0
=> #<Proc:0x028a43a0@(irb):7>
x=foo; y=x(); y
0
1
=> #<Proc:0x028a4538@(irb):7>
x=foo; y=x(); y()
0
1
2
=> #<Proc:0x028a4598@(irb):7>
x=foo(); y=x(); y()
0
1
2
=> #<Proc:0x028a4598@(irb):7>
I think the problem is that you can't have optional ()-arguments and ()
as a call operator as the same time.
this is what I usually thought. After reading the msg [see first msg]
I changed slightly my mind.
However we need optional () because of things like this:
<snip>
yes, totally agree.
···
il Mon, 28 Jun 2004 19:41:54 +0200, Florian Gross <flgr@ccan.de> ha scritto::