[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

No to_d in BigDecimal

Ashley Moran

3/15/2006 12:02:00 PM

Hi everyone

I'm new to the Ruby bandwagon. To get warmed up I've took on the gentle task
of modifiying the PostgreSQL Rails adapter to read and write decimals as
BigDecimals. Oops bad choice :) I'm still working on that though, so I
won't post the half-baked patch yet.

Anyway the immediate issue I have is actually simple. Late last night I
managed to get it reading BigDecimals, but my test case was trying to call
to_d on the objects I was getting back. Can't remember why (it was late -
brain was fried), but I had to open the class and add it in (return self).

This seems like a strange omission from the BigDecimal class. Anyone know if
there's a reason for that? If not could it be added in? I'm scared to touch
it because it's a C library.

Ashley


2 Answers

Kevin Brown

3/17/2006 7:18:00 PM

0

On Wednesday 15 March 2006 06:02, Ashley Moran wrote:
> Hi everyone
>
> I'm new to the Ruby bandwagon. To get warmed up I've took on the gentle
> task of modifiying the PostgreSQL Rails adapter to read and write decimals
> as BigDecimals. Oops bad choice :) I'm still working on that though, so I
> won't post the half-baked patch yet.
>
> Anyway the immediate issue I have is actually simple. Late last night I
> managed to get it reading BigDecimals, but my test case was trying to call
> to_d on the objects I was getting back. Can't remember why (it was late -
> brain was fried), but I had to open the class and add it in (return self).
>
> This seems like a strange omission from the BigDecimal class. Anyone know
> if there's a reason for that? If not could it be added in? I'm scared to
> touch it because it's a C library.

If you're looking for double, then you're probably looking for to_f (float).

> Ashley


Dave Burt

3/17/2006 10:49:00 PM

0

Ashley Moran wrote:
> I'm new to the Ruby bandwagon. To get warmed up I've took on the gentle
> task
> of modifiying the PostgreSQL Rails adapter to read and write decimals as
> BigDecimals. Oops bad choice :) I'm still working on that though, so I
> won't post the half-baked patch yet.
>
> Anyway the immediate issue I have is actually simple. Late last night I
> managed to get it reading BigDecimals, but my test case was trying to call
> to_d on the objects I was getting back. Can't remember why (it was late -
> brain was fried), but I had to open the class and add it in (return self).
>
> This seems like a strange omission from the BigDecimal class. Anyone know
> if
> there's a reason for that? If not could it be added in? I'm scared to
> touch
> it because it's a C library.

Looks to me like it's missing.
How about we add this near line 1310 of ext/bigdecimal/bigdecimal.c?
+ rb_define_method(rb_cBigDecimal, "to_d", BigDecimal_uplus, 0);

Cheers,
Dave