Skip to content

Instantly share code, notes, and snippets.

@stevensona
Last active September 11, 2015 01:21
Show Gist options
  • Save stevensona/dc6e732462f9f22a5581 to your computer and use it in GitHub Desktop.
Save stevensona/dc6e732462f9f22a5581 to your computer and use it in GitHub Desktop.
class Parameter
attr_accessor :value
def initialize(value, update)
@value = value
@update = update
end
def update
@value = @update.call
end
def to_s
@value.to_s
end
end
$sim = Hash.new
def val(param)
$sim[param].value
end
$sim = {
heatIn: Parameter.new(2, Proc.new {val(:heatIn) + 1}),
heatOut: Parameter.new(1, Proc.new {val :heatOut}),
temp: Parameter.new(100, Proc.new {val(:temp) + val(:heatIn) - val(:heatOut)})
}
5.times do |i|
puts "cycle #{i}"
$sim.each do |n, p|
p.update
puts p
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment