Module: Mongoid::Extensions::BigDecimal

Defined in:
lib/mongoid/extensions/big_decimal.rb

Overview

Adds type-casting behavior to BigDecimal class.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Behavior to be invoked when the module is included.

Parameters:

  • base (Module)

    the class or module doing the including



12
13
14
# File 'lib/mongoid/extensions/big_decimal.rb', line 12

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#__to_inc__Float

Deprecated.

Convert the big decimal to an $inc-able value.

Examples:

Convert the big decimal.

bd.__to_inc__

Returns:

  • (Float)

    The big decimal as a float.



23
24
25
# File 'lib/mongoid/extensions/big_decimal.rb', line 23

def __to_inc__
  to_f
end

#mongoizeString | BSON::Decimal128 | nil

Turn the object from the ruby type we deal with to a Mongo friendly type.

Examples:

Mongoize the object.

object.mongoize

Returns:

  • (String | BSON::Decimal128 | nil)

    The object or nil.



35
36
37
# File 'lib/mongoid/extensions/big_decimal.rb', line 35

def mongoize
  ::BigDecimal.mongoize(self)
end

#numeric?true

Is the BigDecimal a number?

Examples:

Is the object a number?.

object.numeric?

Returns:

  • (true)

    Always true.



45
46
47
# File 'lib/mongoid/extensions/big_decimal.rb', line 45

def numeric?
  true
end