1

Is there a ruby equivelent for __rmul__ in ruby? I can't seem to find anything about this.

Sam Hosseini
  • 813
  • 2
  • 9
  • 17
KatGaea
  • 996
  • 1
  • 12
  • 31

3 Answers3

2

not sure about py, but is overloading operator * what you want?

if then, a method * will be fine.

a=Object.new
def a.*(rhs); rhs+2;end

a*2 #=> 4
Jokester
  • 5,501
  • 3
  • 31
  • 39
0

Looking into things further, it seems the equivelent for rmul is to add

def coerce(other)
    return self, other
end

then have the usual * overloaded handle other types too with is_a?

KatGaea
  • 996
  • 1
  • 12
  • 31
0

Check out this discussion here about coerce in Ruby:

In Ruby, how does coerce() actually work?

Community
  • 1
  • 1
robbrit
  • 17,560
  • 4
  • 48
  • 68