Skip to content

Instantly share code, notes, and snippets.

@mlomnicki
Created April 2, 2010 20:27
Show Gist options
  • Save mlomnicki/353665 to your computer and use it in GitHub Desktop.
Save mlomnicki/353665 to your computer and use it in GitHub Desktop.
private method with + w/o self
class A
private
def foo
puts "Private method called"
end
end
class B < A
def call_foo
foo
end
def call_foo_with_self
self.foo
end
end
b = B.new
b.call_foo
b.call_foo_with_self
class A
protected
def foo
puts "Protected method"
end
end
class B < A
def bar
A.new.foo
end
end
# does exactly the same as B but doesn't inherit from A
class C
def bar
A.new.foo
end
end
B.new.bar
A.new.foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment