From: furufuru@... (Ryo Furue) Date: 2001-09-28T14:48:36+09:00 Subject: [ruby-talk:21795] Help: how to (re)define the unary minus? Hi there, I'm wondering how one should (re)define the unary minus operator for a class. The following fails: class Complex attr_accessor :re, :im def initialize(re, im) @re = re; @im = im end def -() # unary??? Complex.new(-@re, -@im) end def to_s "(" + @re.to_s + "," + @im.to_s + ")" end end a = Complex.new(3.14, 1.73) puts -a with ./try.rb:17: undefined method `-@' for # (NameError) I checked the pickaxe book but coudn't find a relevent discussion. Note that what I want to create is not a complex class; I've used it as an obvious example. Cheers, Ryo