Skip to content

Instantly share code, notes, and snippets.

@atoulme
Created December 9, 2011 07:30
Show Gist options
  • Save atoulme/1450622 to your computer and use it in GitHub Desktop.
Save atoulme/1450622 to your computer and use it in GitHub Desktop.
class_methods_and_private.txt
ruby-1.9.3-preview1 :001 > class Foo
ruby-1.9.3-preview1 :002?> private
ruby-1.9.3-preview1 :003?> def self.up
ruby-1.9.3-preview1 :004?> "w00t"
ruby-1.9.3-preview1 :005?> end
ruby-1.9.3-preview1 :006?> end
=> nil
ruby-1.9.3-preview1 :007 > class Bar
ruby-1.9.3-preview1 :008?> class << self
ruby-1.9.3-preview1 :009?> private
ruby-1.9.3-preview1 :010?> def up
ruby-1.9.3-preview1 :011?> "w00t"
ruby-1.9.3-preview1 :012?> end
ruby-1.9.3-preview1 :013?> end
ruby-1.9.3-preview1 :014?> end
=> nil
ruby-1.9.3-preview1 :015 > Foo.up
=> "w00t"
ruby-1.9.3-preview1 :016 > Bar.up
NoMethodError: private method `up' called for Bar:Class
from (irb):16
from /Users/lo/.rvm/rubies/ruby-1.9.3-preview1/bin/irb:16:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment