Created
August 8, 2010 10:23
-
-
Save matthodan/513858 to your computer and use it in GitHub Desktop.
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 characters
#!/usr/bin/env ruby | |
class Parent | |
private | |
def name | |
'Mommy' | |
end | |
end | |
class Child < Parent | |
def get_parent_name | |
puts name # Implicit receiver | |
puts self.name rescue puts 'NoMethodError' # Explicit receiver | |
puts Parent.new.name rescue puts 'NoMethodError' # Explicit receiver | |
end | |
end | |
Child.new.get_parent_name | |
# => Mommy | |
# => NoMethodError | |
# => NoMethodError |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment