Skip to content

Instantly share code, notes, and snippets.

@malclocke
Created August 26, 2015 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malclocke/b2e8c9a9355131d40e44 to your computer and use it in GitHub Desktop.
Save malclocke/b2e8c9a9355131d40e44 to your computer and use it in GitHub Desktop.
class Animal
@@noise = nil
def speak
@@noise
end
end
class Dog < Animal
@@noise = 'Woof'
end
class Cat < Animal
@@noise = 'Meeeeoowww'
end
# > load 'classvars.rb'
# => true
# > Cat.new.speak
# => "Meeeeoowww"
# > Dog.new.speak
# => "Meeeeoowww"
@Br3nda
Copy link

Br3nda commented Aug 26, 2015

heh.

>>> class Animal:
...   noise = None
... 
>>> class Dog(Animal):
...   noise = 'Woof'
... 
>>> class Cat(Animal):
...   noise = 'meow'
... 
>>> 
>>> 
>>> print Cat.noise
meow
>>> print Dog.noise
Woof
>>> 
>>> print Cat().noise
meow
>>> print Dog().noise
Woof

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment