From: Madsen Date: 2005-11-06T22:57:11+09:00 Subject: Re: what does --can't define singleton method-- mean? Daniel Sch�le wrote: > irb(main):005:0> class << c > irb(main):006:1> def angle > irb(main):007:2> (arg/Math::PI)*180 > irb(main):008:2> end > irb(main):009:1> end Do you mean to add a method to an object? This would work: def c.angle (arg/Math::PI)*180 end I hope this will help. > TypeError: can't define singleton method "angle" for Complex > from (irb):6 > from :0 > irb(main):010:0> c.arg > => 0.785398163397448 > irb(main):011:0> c.angle > => 45.0 > irb(main):012:0> > > what does TypeError means here? > can someone enlighten me > I have one more related question > I would like to have the angle method > to return the angle in degrees for each > Complex instance, how can I achieve it > the obvious didn't work for me > > irb(main):014:0* class << Complex > irb(main):015:1> def angle > irb(main):016:2> (self.arg/Math::PI)*180 > irb(main):017:2> end > irb(main):018:1> end > => nil > irb(main):019:0> d=Complex.new 1,1 > => Complex(1, 1) > irb(main):020:0> d > => Complex(1, 1) > irb(main):021:0> d.arg > => 0.785398163397448 > irb(main):022:0> d.angle > => 0.785398163397448 > irb(main):023:0> > > Regards, Daniel