Created
September 11, 2015 13:01
-
-
Save stevensona/20d76f306a66f66680c9 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
class Parameter | |
property value | |
def initialize(value, update) | |
@value = value | |
@update = update | |
end | |
def update | |
@value = @update.call | |
end | |
end | |
$system = {} of Symbol => Parameter | |
def get(param) | |
$system[param].value | |
end | |
def update | |
$system.each { |n, p| p.update } | |
end | |
def display | |
$system.each { |n, p| puts "#{n} = #{p.value}" } | |
end | |
$system = { | |
in: Parameter.new(3, ->{get(:in) + 1}), | |
out: Parameter.new(5, ->{get(:out)}), | |
mass: Parameter.new(100, ->{get(:mass) + get(:in) - get(:out)}) | |
} | |
5.times do | |
update | |
end | |
display |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment