Skip to content

Instantly share code, notes, and snippets.

@stevensona
Created September 11, 2015 13:01
Show Gist options
  • Save stevensona/20d76f306a66f66680c9 to your computer and use it in GitHub Desktop.
Save stevensona/20d76f306a66f66680c9 to your computer and use it in GitHub Desktop.
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