Skip to content

Instantly share code, notes, and snippets.

@atduskgreg
Created September 4, 2008 16:34
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 atduskgreg/8802 to your computer and use it in GitHub Desktop.
Save atduskgreg/8802 to your computer and use it in GitHub Desktop.
module HardwareBase
def self.register_device_type mod, sym
@@device_registrations ||= {}
@@device_registrations[sym] = mod
end
end
module Servo
include HardwareBase
HardwareBase.register_device_type self, :servo
def output_pin_setup(num,opts)
#...do stuff...
end
end
module I2C
include HardwareBase
HardwareBase.register_device_type self, :i2c
def output_pin_setup(num,opts)
#...do stuff...
end
end
class ArduinoSketch
include Servo
include I2C
def initialize
puts @@device_registrations.inspect
end
end
ArduinoSketch.new#.device_registrations.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment