Skip to content

Instantly share code, notes, and snippets.

@kbaird
Created February 15, 2009 17:54
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 kbaird/64793 to your computer and use it in GitHub Desktop.
Save kbaird/64793 to your computer and use it in GitHub Desktop.
#!/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