From: Daniel Vartanov Date: 2008-11-04T18:52:36+09:00 Subject: Conditional overriding of operators Hello! I am trying to replace .+ operator of Numeric class if and only if argument (summand) is my own class. To be more specific: I am writing geometry module in Ruby and need to implement vector-number multiplication so that both: 2 * vector vector * 2 work well. Therefore I need to replace .+ method of Numeric without spoiling arithmetical operations with other classes. It is clear, that in case of inheritance we can just write: class MyNumeric < Numeric def +(object) super(object) unless object.kind_of?(Vector) # vector-number multiplication here... end end But, of course, we need a replacement here. How to implement it? class Numeric def +(vector) unless vector.kinf_of?(Vector) # What to write here??! end # vector-number multiplication here... end -- Posted via http://www.ruby-forum.com/.