T. Onoma
10/12/2004 5:17:00 PM
On Tuesday 12 October 2004 11:49 am, Robert Klemme wrote:
| Why do you need that? Â You *know* the arity because you define the
| argument list between ||.
and
On Tuesday 12 October 2004 12:04 pm, Ara.T.Howard@noaa.gov wrote:
| like this?
|
| Â Â harp:~ > irb
| Â Â irb(main):001:0> cb = proc{|a,b,c| cb.arity}
| Â Â => #<Proc:0xb75a0ecc@(irb):1>
|
| Â Â irb(main):002:0> p cb.call(0,1,2)
| Â Â 3
| Â Â => nil
Well, my example was maybe too simplistic. Procs can be passed around, so, no,
you don't always have a "handle" on them. Moreover, 'this' refers to the
block actually, not really the Proc.
It seems I got my scope wrong, though. But I'm not sure what this scope is
yet.
I should also point out that this idea further derives from speculation (over
on suby-ruby) about internalized counters for #each blocks (and maybe a last?
and first?) eg-
["a","b","c"].each { |x| p this.counter, x }
=> 0
"a"
1
"b"
2
"c"
but I want to focus on the block initself first --hence it's arity.
T.