Created
April 2, 2010 20:27
-
-
Save mlomnicki/353665 to your computer and use it in GitHub Desktop.
private method with + w/o self
This file contains 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 characters
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 |
This file contains 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 characters
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