Skip to content

Instantly share code, notes, and snippets.

@mark
Created July 16, 2013 20:12
Show Gist options
  • Save mark/6012232 to your computer and use it in GitHub Desktop.
Save mark/6012232 to your computer and use it in GitHub Desktop.
1.9.3p194 :001 > class MyClass
1.9.3p194 :002?> protected
1.9.3p194 :003?> def foo; puts "foo"; end
1.9.3p194 :004?> end
=> nil
1.9.3p194 :005 >
1.9.3p194 :006 > class YourClass < MyClass
1.9.3p194 :007?> def call_stuff
1.9.3p194 :008?> foo
1.9.3p194 :009?> YourClass.new.foo
1.9.3p194 :010?> MyClass.new.foo
1.9.3p194 :011?> end
1.9.3p194 :012?> end
=> nil
1.9.3p194 :013 >
1.9.3p194 :014 > class OtherClass
1.9.3p194 :015?> def call_stuff
1.9.3p194 :016?> YourClass.new.foo
1.9.3p194 :017?> MyClass.new.foo
1.9.3p194 :018?> end
1.9.3p194 :019?> end
=> nil
1.9.3p194 :020 > YourClass.new.call_stuff
foo
foo
foo
=> nil
1.9.3p194 :021 > OtherClass.new.call_stuff
NoMethodError: protected method `foo' called for #<YourClass:0x00000100b3e420>
from (irb):16:in `call_stuff'
from (irb):21
from /Users/mark/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>'
1.9.3p194 :022 >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment