# Open +Numeric+ to add new method. class Numeric # Converts this numeric into a +Money+ object in the given +currency+. # # @param [Currency, String, Symbol] currency # The currency to set the resulting +Money+ object to. # # @return [Money] # # @example # 100.to_money #=> # # 100.37.to_money #=> # # BigDecimal.new('100').to_money #=> # # # @see Money.from_numeric # def to_money(currency = nil) Money.deprecate "as of Money 6.1.0 you must `require 'money/core_extension'` to use Numeric#to_money." Money.from_numeric(self, currency || Money.default_currency) end end # Open +String+ to add new methods. class String # Parses the current string and converts it to a +Money+ object. # Excess characters will be discarded. # # @param [Currency, String, Symbol] currency # The currency to set the resulting +Money+ object to. # # @return [Money] # # @example # '100'.to_money #=> # # '100.37'.to_money #=> # # '100 USD'.to_money #=> #> # 'USD 100'.to_money #=> #> # '$100 USD'.to_money #=> #> # 'hello 2000 world'.to_money #=> #> # # @see Money.from_string # def to_money(currency = nil) Money.deprecate "String#to_money is depreciated and will be remove in 6.1.0. Please write your own parsing methods." Money.parse(self, currency) end # Converts the current string into a +Currency+ object. # # @return [Money::Currency] # # @raise [Money::Currency::UnknownCurrency] # If this String reference an unknown currency. # # @example # "USD".to_currency #=> # # def to_currency Money.deprecate "as of Money 6.1.0 you must `require 'money/core_extension'` to use String#to_currency." Money::Currency.new(self) end end # Open +Symbol+ to add new methods. class Symbol # Converts the current symbol into a +Currency+ object. # # @return [Money::Currency] # # @raise [Money::Currency::UnknownCurrency] # If this String reference an unknown currency. # # @example # :ars.to_currency #=> # # def to_currency Money.deprecate "as of Money 6.1.0 you must `require 'money/core_extension'` to use Symbol#to_currency." Money::Currency.new(self) end end