Fixnum.new not working?

S

Schüle Daniel

Hello,

dumb question, why is it forbidden to use
i=Fixnum.new
also Bignum.new
and Float.new
and Complex.new

Regards, Daniel
 
D

Dave Burt

As they say, no such thing as a stupid question, only stupid people.
Just kidding, it's actually a good question.

Further to Robert's explanation, Ruby doesn't want you to worry about
creating numbers. Think of them as values rather than objects, and just
use them.

This lets the classes do smart things behind the scenes like only making
one object per Integer, or automatically reducing Rational numbers.

For Complex numbers and Rational numbers, you can use Complex(r, i) and
Rational(n, d) instead of new.

Cheers,
Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,206
Messages
2,571,069
Members
47,677
Latest member
MoisesKoeh

Latest Threads

Top