[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Question about Ruby philosophy

Yukihiro Matsumoto

12/5/2006 9:04:00 AM

Hi,

In message "Re: Question about Ruby philosophy"
on Tue, 5 Dec 2006 17:20:10 +0900, Robert Klemme <shortcutter@googlemail.com> writes:

|I believe I remember that "1 / 2" used to return "Rational(1, 2)" with
|'rational' loaded. Is my memory wrong here?

Perhaps, you've confused 'rational' and 'mathn'.

matz.

2 Answers

Robert Klemme

12/5/2006 10:29:00 AM

0

On 05.12.2006 10:03, Yukihiro Matsumoto wrote:
> In message "Re: Question about Ruby philosophy"
> on Tue, 5 Dec 2006 17:20:10 +0900, Robert Klemme <shortcutter@googlemail.com> writes:
>
> |I believe I remember that "1 / 2" used to return "Rational(1, 2)" with
> |'rational' loaded. Is my memory wrong here?
>
> Perhaps, you've confused 'rational' and 'mathn'.

Exactly!

>> 1 / 2
=> 0
>> require 'mathn'
=> true
>> 1 / 2
=> 1/2
>> (1 / 2).class
=> Rational

I just notice a strange inconsistency:

>> 12:25:18 [~]: irbs
>> require 'rational'
=> true
>> 1.to_r / 2
=> Rational(1, 2)
>> require 'mathn'
=> true
>> 1 / 2
=> 1/2
>> 1.to_r / 2
=> 1/2

The output of Rational's inspect method seems to change depending on
whether "rational" or "mathn" is required.

Thank you, Matz!

robert

Martin DeMello

12/6/2006 9:19:00 AM

0

On 12/5/06, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:
> Hi,
>
> In message "Re: Question about Ruby philosophy"
> on Tue, 5 Dec 2006 17:20:10 +0900, Robert Klemme <shortcutter@googlemail.com> writes:
>
> |I believe I remember that "1 / 2" used to return "Rational(1, 2)" with
> |'rational' loaded. Is my memory wrong here?
>
> Perhaps, you've confused 'rational' and 'mathn'.

Aha! I was making the same mistake.

martin