Sha256: 20fc9b7187340ac65b9043dbb44f03f67510709922b36f89a256b5534805e812

Contents?: true

Size: 552 Bytes

Versions: 3

Compression:

Stored size: 552 Bytes

Contents

# frozen_string_literal: true

require 'active_support'
require 'active_support/number_helper'
require 'bigdecimal'

Numeric.class_eval do
  include ActiveSupport::NumberHelper

  # Converts a number to a money string
  # @see ActiveSupport::NumberHelper#number_to_currency
  #
  # @param options [Hash]
  #
  # @return [String]
  #
  def to_money(options = { precision: 2, negative_format: '%u(%n)' })
    number_to_currency(to_d, options)
  end
end

String.class_eval do
  # @see Numeric#to_money
  def to_money(...)
    to_d.to_money(...)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby-rails-extensions-2.1.1 lib/ruby-rails-extensions/extensions/to_money.rb
ruby-rails-extensions-2.1.0 lib/ruby-rails-extensions/extensions/to_money.rb
ruby-rails-extensions-2.1.0.pre.rc.14 lib/ruby-rails-extensions/extensions/to_money.rb