AB
Size: a a a
AB
AB
AB
20.usd
10.50.eur
AB
20.usd.to_eur # => (17.7 eur)
AB
AB
require './converter.rb'
# currently, currencies are hardcoded and there are only three of them: usd, eur, rub.
# set up conversion rates. This can be fetched from the internet
ExchangeRate.add_rate(:usd, :rub, 68.7448)
ExchangeRate.add_rate(:eur, :rub, 78.4309)
ExchangeRate.add_rate(:eur, :usd, 1.13)
expenses = 11.eur + 1600.rub # => (11 eur, 1600 rub)
expenses += 2.5.eur
expenses += 30.usd
expenses # => (13.5 eur, 1600 rub, 30 usd)
expenses.to_usd # => (68.53 usd)
М
DR
to_eur(#20.usd)
#17.7eur
- условно говоря. Но спрашивается зачем?DR
~cur(20.usd)
- точнее какой-нибудь сигилой, а печататься будет как #20.usdAB
DR
h Kernel.sigil_C
defmacro sigil_C(term, modifiers)
Handles the sigil ~C for charlists.
It simply returns a charlist without escaping characters and without
interpolations.
## Examples
iex> ~C(foo)
'foo'
iex> ~C(f#{o}o)
'f\#{o}o'
cur
или ещё как-тоDR
FM
100.rub
в руби конечно весело выглядит синтаксически, но это значит, что либа насыпает методов в класс Integer
, т.е. меняет стандартную библиотеку, что ваще грязьМЛ
FM
Integer
будет манкипатчиться динамическиМЛ
FM
Float
10.50.rub