Hi,
Perhaps this is a faq, but I stil don’t understand
the difference between Method and Proc objects.
Is there some pointer to a doc about the this topic.
I read the FAQ, but I found nothing.
My question is : why are there two seemingly
equifunctional classes?
Regards, Christian
“Christian Szegedy” wrote
…
Perhaps this is a faq, but I stil don’t understand
the difference between Method and Proc objects.
Is there some pointer to a doc about the this topic.
I read the FAQ, but I found nothing.
As far as I can tell the only real difference is in the creation
and the fact that you can ``unbind’’ (rebind) a Method.
···
class Fixnum
def foo
p [self,self + 2]
end
end
foo3 = 3.method(:foo)
p foo = foo3.unbind
foo4 = foo.bind(4)
foo6 = foo.bind(6)
(proc {|| }).to_proc
foo3
foo4
foo6
class A
def initialize(x)
@bar = x
end
attr_reader :bar
end
a = A.new “a_foo”
b = A.new “b_foo”
a_bar = a.method(:bar)
b_bar = (a_bar.unbind).bind(b)
proc_bar = proc { || @bar }
@bar = “main_bar”
p a_bar
p b_bar
A.new (“c_bar”).instance_eval {
p proc_bar
}
#<UnboundMethod: Fixnum#foo>
[3, 5]
[4, 6]
[6, 8]
“a_foo”
“b_foo”
“main_bar”
/Christoph
Hello Christian,
Saturday, September 28, 2002, 11:08:35 PM, you wrote:
Hi,
Perhaps this is a faq, but I stil don’t understand
the difference between Method and Proc objects.
question for another big discussion
ruby have three (!) procedure
flavors: method, proc and closure 
···
–
Best regards,
Bulat mailto:bulatz@integ.ru
Christoph wrote:
As far as I can tell the only real difference is in the creation
and the fact that you can ``unbind’’ (rebind) a Method.
Interesting, I have not seen the bind and unbind method
in the Pickaxe book, it seems I should have looked in
Ruby via public_methods.
Thanks for the answer, Christian
Interesting, I have not seen the bind and unbind method
in the Pickaxe book, it seems I should have looked in
Ruby via public_methods.
What is even more interesting …
C:>ri unbind
C:>ruby -Sx C:\ruby\bin\ri.rb unbind
Don’t know anything about a method called `unbind’.
C:>ri bind
C:>ruby -Sx C:\ruby\bin\ri.rb bind
-------------------------------------------------------- Kernel::binding
binding → aBinding
···
Returns a Binding object, describing the variable and method
bindings at the point of call. This object can be used when calling
eval to execute the evaluated command in this environment. Also see
the description of Binding beginning on page 295.
def getBinding(param)
return binding
end
b = getBinding("hello")
eval "param", b #=> "hello"
C:>ri rebind
C:>ruby -Sx C:\ruby\bin\ri.rb rebind
Don’t know anything about a method called `rebind’.
C:>ri -v
C:>ruby -Sx C:\ruby\bin\ri.rb -v
ri 0.8a
C:>
Hello Yukihiro,
Monday, September 30, 2002, 11:58:29 AM, you wrote:
question for another big discussion
ruby have three (!) procedure
flavors: method, proc and closure 
Ruby’s closure is a proc.
kernel::proc creates a procedure from closure
···
–
Best regards,
Bulat mailto:bulatz@integ.ru
“Shashank Date” wrote
…
C:>ri rebind
C:>ruby -Sx C:\ruby\bin\ri.rb rebind
Don’t know anything about a method called `rebind’.
I used the term ``rebind’’ in a colloquial sense,. It is not
an instance method of the relevant classes Proc, Method
or UnBoundMethod.
/Christoph
unbind and bind are new to 1.7.
-rich
···
-----Original Message-----
From: Shashank Date [mailto:sdate@kc.rr.com]
Sent: Sunday, September 29, 2002 5:59 PM
To: ruby-talk ML
Subject: Re: Method <=> Proc
Interesting, I have not seen the bind and unbind method
in the Pickaxe book, it seems I should have looked in
Ruby via public_methods.
What is even more interesting …
C:>ri unbind
C:>ruby -Sx C:\ruby\bin\ri.rb unbind
Don’t know anything about a method called `unbind’.
C:>ri bind
C:>ruby -Sx C:\ruby\bin\ri.rb bind
Kernel::binding
binding → aBinding
Returns a Binding object, describing the variable and method
bindings at the point of call. This object can be used
when calling
eval to execute the evaluated command in this
environment. Also see
the description of Binding beginning on page 295.
def getBinding(param)
return binding
end
b = getBinding(“hello”)
eval “param”, b #=> “hello”
C:>ri rebind
C:>ruby -Sx C:\ruby\bin\ri.rb rebind
Don’t know anything about a method called `rebind’.
C:>ri -v
C:>ruby -Sx C:\ruby\bin\ri.rb -v
ri 0.8a
C:>
The main point is, however, that ‘ri’ doesn’t know about ‘bind’ or ‘unbind’.
Nor does it know about UnboundMethod.
Gavin
···
----- Original Message -----
From: “Christoph” chr_news@gmx.net
“Shashank Date” wrote
…
C:>ri rebind
C:>ruby -Sx C:\ruby\bin\ri.rb rebind
Don’t know anything about a method called `rebind’.
I used the term ``rebind’’ in a colloquial sense,. It is not
an instance method of the relevant classes Proc, Method
or UnBoundMethod.
/Christoph
I beg to differ. I’m using 1.6.5 on Cygwin and followed Christoph’s very
entertaining example (thanks, Christoph) no problem.
Gavin
···
----- Original Message -----
From: “Rich Kilmer” rich@infoether.com
unbind and bind are new to 1.7.
-rich
You are right…I appologize…they were added in 1.6.2:
-rich
···
-----Original Message-----
From: Gavin Sinclair [mailto:gsinclair@soyabean.com.au]
Sent: Sunday, September 29, 2002 11:35 PM
To: ruby-talk ML
Subject: Re: Method <=> Proc
----- Original Message -----
From: “Rich Kilmer” rich@infoether.com
unbind and bind are new to 1.7.
-rich
I beg to differ. I’m using 1.6.5 on Cygwin and followed
Christoph’s very entertaining example (thanks, Christoph) no problem.
Gavin