Created
September 19, 2012 11:37
-
-
Save jonesdeini/3749204 to your computer and use it in GitHub Desktop.
Revisions
-
jonesdeini created this gist
Sep 19, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,66 @@ class Parent def mr_public 'public' end def access_other_protected(other) other.mr_protected end def access_other_private(other) other.mr_private end def access_self_protected self.mr_protected end def access_self_private self.mr_private end protected def mr_protected 'protected' end private def mr_private 'private' end end class Child < Parent def access_parent_protected mr_protected end def access_parent_private mr_private end end def attempt puts yield rescue puts 'forbidden' end parent = Parent.new other = Parent.new child = Child.new attempt { parent.mr_public } attempt { parent.mr_protected } attempt { parent.mr_private } attempt { parent.access_self_protected } attempt { parent.access_self_private } attempt { parent.access_other_protected(other) } attempt { parent.access_other_private(other) } attempt { child.access_parent_protected } attempt { child.access_parent_private }