[rspec-users] any tricks re using " eql(5.5)", but where 5.5 is a decimal not float?

Mark Wilden mark at mwilden.com
Fri Nov 7 19:09:55 EST 2008

On Fri, Nov 7, 2008 at 3:51 PM, Pat Maddox <pergesu at gmail.com> wrote:

> "Greg Hauptmann" <greg.hauptmann.ruby at gmail.com> writes:
> Do you mean BigDecimal?  Anyway, you should probably be using == instead
> of eql.
> >> 5.5 == BigDecimal.new('5.5')
> => true
> >> 5.5.eql? BigDecimal.new('5.5')
> => false
> eql? is object identity and is generally not what you're after.

Yeah, but

>> BigDecimal('5.5').eql? BigDecimal('5.5')
=> true

So it's either creating value objects (like Symbol) or BigDecimal.eql?
doesn't do object equality.

What's interesting is that you can create BigDecimals this way (without
calling new). You can do it with Strings, too.

>> String('asdf')
=> "asdf"

But not everything:

>> Hash(:a => 5)
NoMethodError: undefined method `Hash' for #<Object:0x3799c>
    from (irb):12

As Johnny Carson used to say, "I did not know that."

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081107/db95fe98/attachment.html>

More information about the rspec-users mailing list