Skip to content

Instantly share code, notes, and snippets.

@ab
Created July 5, 2017 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ab/2185071003e95c1510f446584394e87f to your computer and use it in GitHub Desktop.
Save ab/2185071003e95c1510f446584394e87f to your computer and use it in GitHub Desktop.
Case study to demonstrate jruby block bug https://github.com/jruby/jruby/issues/4217
#!/usr/bin/env ruby
class Foo
attr_reader :failed
def initialize
@failed = false
end
def [](foo, &block)
if block_given?
puts "block_given, block: " + block.inspect
else
puts "NOT block_given, block: " + block.inspect
@failed = true
end
end
def test_method(foo, &block)
if block_given?
puts "block_given, block: " + block.inspect
else
puts "NOT block_given, block: " + block.inspect
@failed = true
end
end
end
f = Foo.new
puts '--'
puts RUBY_DESCRIPTION
block = proc {|r| r}
puts
puts 'Test 1: f[&block]'
f['foo', &block]
puts
puts 'Test 2: test_method(&block)'
f.test_method('foo', &block)
puts
puts 'Test 3: f.[](&block)'
f.[]('foo', &block)
puts
puts 'Test 4: f.public_send(:[], &block)'
f.public_send(:[], 'foo', &block)
if f.failed
puts 'FAILED'
exit 1
else
puts 'Succeeded'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment