Skip to content

Instantly share code, notes, and snippets.

@Sailias
Created April 19, 2013 14:49
Show Gist options
  • Save Sailias/5420834 to your computer and use it in GitHub Desktop.
Save Sailias/5420834 to your computer and use it in GitHub Desktop.
#!/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