Sha256: dee4b0ca8db71b6e9b9d785ade35612967b839c75e92e26855d06951fbf557d0

Contents?: true

Size: 865 Bytes

Versions: 1

Compression:

Stored size: 865 Bytes

Contents

# coding: utf-8

module Nephos

  # Params to a hash, where every elements are accessibles via a stringified key
  # so, even if the entry was added with the key :KEY, it will be accessible via
  # a string equivalent to :key.to_s
  #   param["key"] == param[:key]
  #
  # Every methods present in {Hash} are usable in {Param}.
  class Params

    # @param hash [Hash] hash containing the parameters
    def initialize(hash={})
      raise ArgumentError, "the first argument must be a Hash" unless hash.is_a? Hash
      @hash = Hash[hash.map{|k,v| [k.to_s, v]}]
    end

    def method_missing m, *a
      @hash.send(m, *(a.map(&:to_s)))
    end

    def [] i
      @hash[i.to_s]
    end

    def []= i, v
      @hash[i.to_s] = v.to_s
    end

    def to_h
      return @hash
    end
    alias :to_hash :to_h

    def to_s
      return to_h.to_s
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nephos-server-0.7.2 lib/nephos-server/params.rb