Created
January 6, 2014 14:13
-
-
Save jeremywrowe/8283389 to your computer and use it in GitHub Desktop.
This is a display of taking advantage of ruby 2.1 returning a symbol representation of methods when created and passing it to private as a single argument.
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 Test | |
# :( wish this worked | |
private def self.bar | |
puts "self bar" | |
end | |
# would be nice to not have to do this | |
class << self | |
private def nook | |
puts "self nook" | |
end | |
end | |
# not private! | |
def foo | |
puts "foo" | |
end | |
end | |
test = Test.new | |
test.foo #=> "foo" | |
Test.bar #=> "bar" -- :( | |
Test.nook #=> private method `nook' called for Test:Class (NoMethodError) -- YAY! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment