Module: Money::Constructors

Included in:
Money
Defined in:
lib/money/money/constructors.rb

Instance Method Summary collapse

Instance Method Details

#ca_dollar(cents) ⇒ Money Also known as: cad

Creates a new Money object of the given value, using the Canadian dollar currency.

Examples:

n = Money.ca_dollar(100)
n.cents    #=> 100
n.currency #=> #<Money::Currency id: cad>

Parameters:

  • cents (Integer)

    The cents value.

Returns:


29
30
31
# File 'lib/money/money/constructors.rb', line 29

def ca_dollar(cents)
  new(cents, "CAD")
end

#empty(currency = default_currency) ⇒ Money Also known as: zero

Create a new money object with value 0.

Examples:

Money.empty #=> #<Money @fractional=0>

Parameters:

  • currency (Currency, String, Symbol) (defaults to: default_currency)

    The currency to use.

Returns:


12
13
14
# File 'lib/money/money/constructors.rb', line 12

def empty(currency = default_currency)
  new(0, currency)
end

#euro(cents) ⇒ Money Also known as: eur

Creates a new Money object of the given value, using the Euro currency.

Examples:

n = Money.euro(100)
n.cents    #=> 100
n.currency #=> #<Money::Currency id: eur>

Parameters:

  • cents (Integer)

    The cents value.

Returns:


62
63
64
# File 'lib/money/money/constructors.rb', line 62

def euro(cents)
  new(cents, "EUR")
end

#pound_sterling(pence) ⇒ Money Also known as: gbp

Creates a new Money object of the given value, in British pounds.

Examples:

n = Money.pound_sterling(100)
n.fractional    #=> 100
n.currency #=> #<Money::Currency id: gbp>

Parameters:

  • pence (Integer)

    The pence value.

Returns:


78
79
80
# File 'lib/money/money/constructors.rb', line 78

def pound_sterling(pence)
  new(pence, "GBP")
end

#us_dollar(cents) ⇒ Money Also known as: usd

Creates a new Money object of the given value, using the American dollar currency.

Examples:

n = Money.us_dollar(100)
n.cents    #=> 100
n.currency #=> #<Money::Currency id: usd>

Parameters:

  • cents (Integer)

    The cents value.

Returns:


46
47
48
# File 'lib/money/money/constructors.rb', line 46

def us_dollar(cents)
  new(cents, "USD")
end