M
Mike Ho
Hi,
I've written a simplistic override of the * operator for Arrays so that
[2,4,6]*[2,2,2] = [4,8,12]
class Array
def *(other)
each_with_index do |x,i|
self= x * other
end
end
end
It assumes that the arrays are the same length and no error checking is
done.
My questions are; is this idiomatic Ruby?
What solution would an experienced Rubyist offer?
How would it be best to handle exceptions when the arrays are of
different dimensions and/or length?
Many Thanks
Mike
I've written a simplistic override of the * operator for Arrays so that
[2,4,6]*[2,2,2] = [4,8,12]
class Array
def *(other)
each_with_index do |x,i|
self= x * other
end
end
end
It assumes that the arrays are the same length and no error checking is
done.
My questions are; is this idiomatic Ruby?
What solution would an experienced Rubyist offer?
How would it be best to handle exceptions when the arrays are of
different dimensions and/or length?
Many Thanks
Mike