[MacRuby] #1177: Hash.each doesn't exit on embedded return
MacRuby
ruby-noreply at macosforge.org
Thu Mar 3 13:47:13 PST 2011
#1177: Hash.each doesn't exit on embedded return
-------------------------------+--------------------------------------------
Reporter: dopperman@… | Owner: lsansonetti@…
Type: defect | Status: new
Priority: blocker | Milestone:
Component: MacRuby | Keywords: Hash each
-------------------------------+--------------------------------------------
i isolated this as best i could. the hash.each loop in the weirdness
method does not exit on return. instead, it jumps to the top of the loop
and continues to iterate through the hash. replacing the line
@map.each do |letters, numbers|
with
@map.keys.each do |letters|
produces the correct behavior. Hash.each and Hash.each_key produce
identical results. Not sure this is a high priority since iterating
through the Hash.keys array works.
class A
def initialize(parent)
@map = Hash[ 'a', 1, 'b', 2, 'c', 3, 'd', 4]
@parent = parent
end
def test
@parent.thread_me_back { weirdness }
end
def weirdness
@map.each do |letters, numbers| # bug lies here
puts 'top of loop'
if @parent.aborted?
puts 'leaving...'
return
end
sleep(1)
end
end
end
class B
def initialize
@abort_signal = false
@thread = nil
end
def run
a = A.new(self)
a.test
sleep(1)
@abort_signal = true
@thread.join
end
def thread_me_back(&block)
@thread = Thread.new do
yield
end
end
def aborted?
return @abort_signal
end
end
B.new.run
--
Ticket URL: <http://www.macruby.org/trac/ticket/1177>
MacRuby <http://macruby.org/>
More information about the macruby-tickets
mailing list