Created
July 5, 2017 05:05
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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