Created
February 15, 2009 17:54
-
-
Save kbaird/64793 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
#!/usr/bin/env ruby | |
# vehicle.rb | |
class Vehicle | |
MEDIUM = :ground | |
def self.medium; self::MEDIUM; end | |
# Using MEDIUM instead of self::MEDIUM makes Aircraft use the ground | |
end | |
class Car < Vehicle; end | |
module Flyable | |
MEDIUM = :air | |
end | |
class Aircraft < Vehicle | |
include Flyable | |
end | |
if (__FILE__ == $0) | |
puts File.read(__FILE__) | |
puts | |
puts 'Produces:' | |
puts | |
[Vehicle, Car, Aircraft].each do |klass| | |
puts "#{klass}.medium = #{klass.medium}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment