Skip to content

Instantly share code, notes, and snippets.

@nwjsmith
Created May 14, 2015 20:20
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 nwjsmith/33671d46e54f25a0e752 to your computer and use it in GitHub Desktop.
Save nwjsmith/33671d46e54f25a0e752 to your computer and use it in GitHub Desktop.
Delegates can use `#public_send` even though they inherit from `BasicObject`
Run options: --seed 53381
# Running:
.
Finished in 0.000873s, 1145.2393 runs/s, 1145.2393 assertions/s.
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
require 'minitest/autorun'
class Decorator < SimpleDelegator
def decorated
public_send(:original)
end
def original
'wat'
end
end
class DecoratorTest < Minitest::Test
def test_delegate_behaves_strangely
decorator = Decorator.new(BasicObject.new)
assert_equal 'wat', decorator.decorated
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment