Skip to content

Instantly share code, notes, and snippets.

@jeremywrowe
Created January 6, 2014 14:13
Show Gist options
  • Save jeremywrowe/8283389 to your computer and use it in GitHub Desktop.
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.
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