D
Daniel Schüle
RubyNG.hello /.*/
mond:/pool/PROG/ruby # irb
irb(main):001:0> require "complex"
=> true
irb(main):002:0> c=Complex.new 1,1
=> Complex(1, 1)
irb(main):003:0> c.arg
=> 0.785398163397448
irb(main):004:0> c.angle
=> 0.785398163397448
irb(main):005:0> class << c
irb(main):006:1> def angle
irb(main):007:2> (arg/Math:I)*180
irb(main):008:2> end
irb(main):009:1> end
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:I)*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
mond:/pool/PROG/ruby # irb
irb(main):001:0> require "complex"
=> true
irb(main):002:0> c=Complex.new 1,1
=> Complex(1, 1)
irb(main):003:0> c.arg
=> 0.785398163397448
irb(main):004:0> c.angle
=> 0.785398163397448
irb(main):005:0> class << c
irb(main):006:1> def angle
irb(main):007:2> (arg/Math:I)*180
irb(main):008:2> end
irb(main):009:1> end
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:I)*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