Created
April 19, 2013 14:49
-
-
Save Sailias/5420834 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
class Device | |
attr_accessor :name | |
attr_reader :calculations | |
def initialize | |
@calculations = [] | |
end | |
def build_calculation(name) | |
calculation = Calculation.new | |
calculation.name = name | |
@calculations << calculation | |
extend Object.const_get("Methods").const_get(name) | |
end | |
end | |
class Calculation | |
attr_accessor :name | |
end | |
module Methods | |
module NickMath | |
def sum(a,b) | |
a + b | |
end | |
end | |
end | |
module Methods | |
module Jon | |
def program | |
puts "Jon is beginning to program" | |
end | |
end | |
end | |
device = Device.new | |
device.name = "My Device" | |
device.build_calculation("NickMath") | |
s = device.sum(1,2) | |
puts "The sum of the numbers is #{s}" | |
device.build_calculation("Jon") | |
device.program |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment