CD-RUM CD-RUM - 1 month ago 18
Ruby Question

Ruby: reverse calculation or spreadsheet function

I've got a module that calculates about 150-200 values. Once it's done, I want the ability to edit one or some of the results—which may or may not be one of the original, non-calculated values—and have the other results update, like the functionality of a spreadsheet.

The problem is I really don't know where to start. The module's code looks largely like this:

if @user.override > 0
h[:floor] += (@user.override / h[:size]) * 0.03
end

if @user.other_override > 0
h[:floor] += (@user.other_override / h[:size]) * 0.03
end


And is quite chronological, making this task even tougher.

Is there any approach here that'll work? I can barely wrap my head around how it might, other than to leverage an actual spreadsheet into my app.

Answer

What you are looking for is called "Reactive Programming". Many languages have an implementation of the ReactiveX framework, so does Ruby: RxRuby