Skip to content

Instantly share code, notes, and snippets.

@modsognir
Created August 26, 2015 04:01
Show Gist options
  • Save modsognir/e1782a0519615d8f179e to your computer and use it in GitHub Desktop.
Save modsognir/e1782a0519615d8f179e to your computer and use it in GitHub Desktop.
class Animal
def self.noise=(sound)
@noise = sound
end
def self.noise
@noise
end
def speak
self.class.noise
end
end
class Dog < Animal
self.noise = 'Woof'
end
class Cat < Animal
self.noise = 'Meeeeoowww'
end
> Cat.new.speak
=> "Meeeeoowww"
> Dog.new.speak
=> "Woof"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment