Last active
August 29, 2015 14:01
-
-
Save ejfinneran/90694503baea1d5c1cb3 to your computer and use it in GitHub Desktop.
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
gem 'minitest' |
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
class Object | |
alias_method :unsafe_send, :send | |
alias_method :safe_send, :public_send | |
alias_method :send, :safe_send | |
end | |
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
require './safe_send' | |
require 'minitest/autorun' | |
class MyClass | |
def my_public_method | |
"Hello" | |
end | |
private | |
def my_private_method | |
"Get out of here!" | |
end | |
end | |
describe MyClass do | |
it "should allow me to call #my_public_method" do | |
MyClass.new.my_public_method.must_equal "Hello" | |
end | |
it "should not allow me to call #my_private_method" do | |
MyClass.new.my_public_method.must_equal "Hello" | |
end | |
it "should not allow me to call #my_private_method" do | |
assert_raises(NoMethodError) { | |
MyClass.new.my_private_method | |
} | |
end | |
it "should not allow me to call #my_private_method using send" do | |
assert_raises(NoMethodError) { | |
MyClass.new.send(:my_private_method) | |
} | |
end | |
end |
Author
ejfinneran
commented
May 30, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment