Skip to content

Instantly share code, notes, and snippets.

@matthodan
Created August 8, 2010 10:23
Show Gist options
  • Save matthodan/513858 to your computer and use it in GitHub Desktop.
Save matthodan/513858 to your computer and use it in GitHub Desktop.
#!/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