Skip to content

Instantly share code, notes, and snippets.

@bcardarella
Created June 10, 2013 03:55
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 bcardarella/5746455 to your computer and use it in GitHub Desktop.
Save bcardarella/5746455 to your computer and use it in GitHub Desktop.
require 'minitest/autorun'
module A; end
class Person; end
class User
prepend A
end
kode = <<-RUBY_EVAL
def tester
'It works!'
end
protected :tester
RUBY_EVAL
Person.class_eval(kode, __FILE__, __LINE__ + 1)
User.class_eval(kode, __FILE__, __LINE__ + 1)
describe Person do
it 'prints the message' do
Person.new.send(:tester).must_equal 'It works!'
end
end
describe User do
it 'prints the message' do
# won't work because the the top ancestor of the User
# receiver is not User. Protected method cannot be accessed
User.new.send(:tester).must_equal 'It works!'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment