DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Ruby Blocks Are Bad Designed.

03.21.2010
| 2453 views |
  • submit to reddit
        I know I know its a feature not a bug! Now run away you stupid ruby fanbois!

def zork(up)
  puts 'foo'
  up.call(42)
  puts 'bar'
end
up = Proc.new do |n|
  return if n == 42
  puts 'foo'
end
zork(up)
#>>> foo
#>>> ... unexpected return (LocalJumpError)

def zork
  puts 'foo'
  up = Proc.new do |n|
    return if n == 42
    puts 'foo'
  end
  bla = up.call(42)
  puts 'bar'
end
zork
puts "baz"
#>>> foo
#>>> baz

def zork
  puts 'foo'
  up = lambda do |n|
    return if n == 42
    puts 'foo'
  end
  bla = up.call(42)
  puts 'bar'
end
zork
puts "baz"
#>>> foo
#>>> bar
#>>> baz