Class: HyperResource::Objects

Inherits:
Hash
  • Object
show all
Defined in:
lib/hyper_resource/objects.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource = nil) ⇒ Objects

Returns a new instance of Objects.



5
6
7
# File 'lib/hyper_resource/objects.rb', line 5

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Raises:

  • (NoMethodError)


29
30
31
32
# File 'lib/hyper_resource/objects.rb', line 29

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

Instance Attribute Details

#_resourceObject

Returns the value of attribute _resource.



3
4
5
# File 'lib/hyper_resource/objects.rb', line 3

def _resource
  @_resource
end

Instance Method Details

#[](key) ⇒ Object

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.



17
18
19
20
21
22
23
24
25
26
# File 'lib/hyper_resource/objects.rb', line 17

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

#[]=(attr, value) ⇒ Object



10
11
12
# File 'lib/hyper_resource/objects.rb', line 10

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

#respond_to?(method, *args) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
# File 'lib/hyper_resource/objects.rb', line 35

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