読者です 読者をやめる 読者になる 読者になる

RubyMotionでブロック中のblock_given?の値が変わる

RubyMotion

これではまった。
https://gist.github.com/ainame/5651453

yieldも同じようにダメっぽい。

def callback_caller
  callback_caller2 do
    yield
  end
end
 
def callback_caller2(&block)
  block.call
end
 
callback_caller do
  p 'origin'
end
# CRuby 1.9.3
$ ruby sample.rb
"origin"

# ruby motion 2.5
$ /Library/RubyMotion/bin/ruby sample.rb 
2013-07-25 22:59:58.924 ruby[89777:707] /Users/hokamura/Works/tmp/sample.rb:3:in `block': no block given (LocalJumpError)
        from /Users/hokamura/Works/tmp/sample.rb:8:in `callback_caller2'
        from /Users/hokamura/Works/tmp/sample.rb:2:in `callback_caller'
        from /Users/hokamura/Works/tmp/sample.rb:11:in `<main>'
/Users/hokamura/Works/tmp/sample.rb:3:in `block': no block given (LocalJumpError)
        from /Users/hokamura/Works/tmp/sample.rb:8:in `callback_caller2'
        from /Users/hokamura/Works/tmp/sample.rb:2:in `callback_caller'
        from /Users/hokamura/Works/tmp/sample.rb:11:in `<main>'

ちなみにcallback_caller2の処理をyieldにするとRubyMotionでもいける。

def callback_caller
  callback_caller2 do
    yield
  end
end
 
def callback_caller2
  yield
end
 
callback_caller do
  p 'origin'
end
# ruby motion 2.5
$ /Library/RubyMotion/bin/ruby sample.rb
"origin" 

うーむ・・。