Sha256: 159fbee1e4a5650c716af7d80fdc11466465b7d3f45a4f1a8a203b3106e00d51

Contents?: true

Size: 994 Bytes

Versions: 6

Compression:

Stored size: 994 Bytes

Contents

class HyperResource
  class Objects < Hash
    attr_accessor :_resource

    def initialize(resource=nil) 
      self._resource = resource || HyperResource.new
    end

    # @private
    def []=(attr, value)
      super(attr.to_s, value)
    end

    ## When +key+ is a string, returns the array of objects under that name.
    ## When +key+ is a number, returns +ith(key)+. Returns nil on lookup
    ## failure.
    def [](key)
      case key
      when String, Symbol
        return super(key.to_s) if self.has_key?(key.to_s)
        return super(key.to_sym) if self.has_key?(key.to_sym)
      when Fixnum
        return ith(key)
      end
      nil
    end

    # @private
    def method_missing(method, *args)
      return self[method] if self[method]
      raise NoMethodError, "undefined method `#{method}' for #{self.inspect}"
    end

    # @private
    def respond_to?(method, *args)
      method = method.to_s
      return true if self.has_key?(method)
      super
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
hyperresource-0.9.4 lib/hyper_resource/objects.rb
hyperresource-0.9.3 lib/hyper_resource/objects.rb
hyperresource-0.9.2 lib/hyper_resource/objects.rb
hyperresource-0.9.1 lib/hyper_resource/objects.rb
hyperresource_zuhrig-0.1.0 lib/hyper_resource/objects.rb
hyperresource-0.9.0 lib/hyper_resource/objects.rb