[MacRuby-devel] enumerateObjectsUsingBlock
Alan Skipp
al_skipp at fastmail.fm
Wed Jan 12 01:03:44 PST 2011
Hi everyone,
Below is a reduction of a problem I've noticed when using 'enumerateObjectsUsingBlock' from inside a proc. The line which causes trouble is:
[1,2,3].enumerateObjectsUsingBlock( Proc.new { |o, i, s| puts "inner enumeration #{o}" } )
If this line is replaced with:
[1,2,3].each { |e| puts "inner enumeration #{e}" }
Then the code behaves as expected.
framework 'Foundation'
proc = Proc.new do |arg|
[1,2,3].enumerateObjectsUsingBlock( Proc.new { |o, i, s| puts "inner enumeration #{o}" } )
puts arg.upcase
end
%w[a b c].enumerateObjectsUsingBlock( Proc.new do |obj, idx, stop|
proc.call(obj)
end
)
The output is as follows:
inner enumeration 1
inner enumeration 2
inner enumeration 3
A
inner enumeration b
inner enumeration c
The output I would expect is this:
inner enumeration 1
inner enumeration 2
inner enumeration 3
A
inner enumeration 1
inner enumeration 2
inner enumeration 3
B
inner enumeration 1
inner enumeration 2
inner enumeration 3
C
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20110112/4a882181/attachment.html>
More information about the MacRuby-devel
mailing list