Sha256: 679ee68aa998f430a9bc5620e6cacb1326cf23154de0ed693d95c9628e925e6e

Contents?: true

Size: 545 Bytes

Versions: 3

Compression:

Stored size: 545 Bytes

Contents

module Economy
  class Currencies

    def exist?(id)
      registry.has_key? id
    end

    def find(id)
      if exist?(id)
        registry[id]
      else
        raise "Currency #{id} not found"
      end
    end

    def add(*args)
      currency = Currency.new(*args)
      registry[currency.iso_code] = currency
    end

    %i(each map).each do |name|
      define_method name do |*args, &block|
        registry.values.send name, *args, &block
      end
    end

    private

    def registry
      @registry ||= {}
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
economy-4.0.1.0 lib/economy/currencies.rb
economy-4.0.0.0 lib/economy/currencies.rb
economy-0.0.1 lib/economy/currencies.rb