Martin DeMello
10/13/2008 9:35:00 AM
On Mon, Oct 13, 2008 at 1:02 AM, Robert Klemme
<shortcutter@googlemail.com> wrote:
> 2008/10/12 David A. Black <dblack@rubypal.com>:
>> On Mon, 13 Oct 2008, Phlip wrote:
>
>>> Ruby has no procedures, only methods. All methods have a hidden 'self'
>>> variable linking them to an object.
>>
>> I think you missed the "(Proc)" in the question. The question is about
>> Proc objects (which I think it's reasonable to refer to as procedures,
>> though typically people don't) in comparison with methods.
>
> IMHO it makes sense to not refer to Procs as "procedures" because they
> actually are _closures_. This is a significant difference.
For the original poster, here's a quick illustration:
$ cat test.rb
a = 42
def foo
puts a
end
bar = Proc.new { puts a }
puts "calling bar"
bar.call
puts "calling foo"
foo
$ ruby test.rb
calling bar
42
calling foo
test.rb:4:in `foo': undefined local variable or method `a' for
main:Object (NameError)
from test.rb:13