Sha256: 83462891ff8b8d70345a22f43e994fa6f21bbce6f21435f03dca0da2e860ed53

Contents?: true

Size: 501 Bytes

Versions: 4

Compression:

Stored size: 501 Bytes

Contents

module Economy
  class Currencies

    def find(id)
      if registry.has_key?(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

4 entries across 4 versions & 1 rubygems

Version Path
economy-5.1.0 lib/economy/currencies.rb
economy-4.0.2.2 lib/economy/currencies.rb
economy-4.0.2.1 lib/economy/currencies.rb
economy-4.0.2.0 lib/economy/currencies.rb