You shouldn’t try to translate code word by word. This simply does not
work (just like with natural languages).
First of all, Ruby uses class based inheritance and not prototype bases
inheritance. So instead of adding a method to the prototype of
TimeSeries, you would open the class TimeSeries and define a new method.
Defining a method is also completely different in JavaScript and Ruby.
In JavaScript, you create a function object and store it in an attribute
of the object. In Ruby, you simply write a method definition:
class TimeSeries
def append timestamp, value @data << [timestamp, value] @max_value = value unless @max_value and @max_value >= value @min_value = value unless @min_value and @min_value <= value
end
end
Personally I find this much more intuitive and simple than the
JavaScript code.
On Saturday, March 17, 2012 5:08:24 PM UTC-7, Jan E. wrote:
class TimeSeries
def append timestamp, value @data << [timestamp, value] @max_value = value unless @max_value and @max_value >= value @min_value = value unless @min_value and @min_value <= value