Created
March 25, 2009 11:44
-
-
Save jimweirich/85433 to your computer and use it in GitHub Desktop.
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 Animal | |
def set_from_animal | |
@@x = :animal | |
end | |
def get_from_animal | |
@@x | |
end | |
end | |
class Dog < Animal | |
def set_from_dog | |
@@x = :dog | |
end | |
def get_from_dog | |
@@x | |
end | |
end | |
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
require 'animals' | |
Dog.new.set_from_dog | |
Animal.new.set_from_animal | |
# Animal and Dog have distinct @@x variables | |
puts Animal.new.get_from_animal | |
puts Dog.new.get_from_dog |
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
$ ruby shared.rb | |
dog | |
dog | |
$ | |
$ ruby distinct.rb | |
animal | |
dog | |
$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment