Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Why does :explodes raise LocalJumpError: no block given (yield)?
class Dynamical
define_method :works_fine do |&block|
5.times { |n| block.call(n) }
end
def also_works_fine(&block)
5.times { |n| block.call(n) }
end
define_method :explodes do |&block|
5.times { |n| yield n }
end
def seems_like_it_should_explode
5.times { |n| yield n }
end
end
d = Dynamical.new
d.works_fine {|x| puts x}
d.also_works_fine {|x| puts x}
d.seems_like_it_should_explode {|x| puts x}
d.explodes {|x| puts x}
@thejonanshow

This comment has been minimized.

Copy link
Owner Author

@thejonanshow thejonanshow commented Oct 20, 2014

ruby dynamical.rb
0
1
2
3
4
0
1
2
3
4
0
1
2
3
4
LocalJumpError: no block given (yield)
from /Users/jonan/Dropbox/conferences/keep_ruby_weird/main.rb:21:in `block (2 levels) in <class:Dynamical>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment