Skip to content

Instantly share code, notes, and snippets.

@jonesdeini
Created September 19, 2012 11:37
Show Gist options
  • Save jonesdeini/3749204 to your computer and use it in GitHub Desktop.
Save jonesdeini/3749204 to your computer and use it in GitHub Desktop.
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 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment