Sha256: 12859334f0458c129757fb92345a3934dc38723606d0e05ff4b4a5b2139d2d09
Contents?: true
Size: 1.56 KB
Versions: 2
Compression:
Stored size: 1.56 KB
Contents
class HyperResource class Objects < Hash attr_accessor :_resource def initialize(resource=nil) self._resource = resource || HyperResource.new end ## Creates accessor methods in self.class and self._resource.class. ## Protects against method creation into HyperResource::Objects and ## HyperResource classes. Just subclasses, please! def create_methods!(opts={}) return if self.class.to_s == 'HyperResource::Objects' || self._resource.class.to_s == 'HyperResource' self.keys.each do |attr| attr_sym = attr.to_sym self.class.send(:define_method, attr_sym) do self[attr] end ## Don't stomp on _resource's methods unless _resource.respond_to?(attr_sym) _resource.class.send(:define_method, attr_sym) do objects.send(attr_sym) end end end end ## Returns the first item in the first collection in +self+. alias_method :first_orig, :first def first self.first_orig[1][0] end ## Returns the ith item in the first collection in +self+. def ith(i) self.first_orig[1][i] end def []=(attr, value) # :nodoc: super(attr.to_s, value) end def [](key) # :nodoc: return super(key.to_s) if self.has_key?(key.to_s) return super(key.to_sym) if self.has_key?(key.to_sym) nil end def method_missing(method, *args) # :nodoc: return self[method] if self[method] raise NoMethodError, "undefined method `#{method}' for #{self.inspect}" end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
hyperresource-0.1.9.5 | lib/hyper_resource/objects.rb |
hyperresource-0.1.9.4 | lib/hyper_resource/objects.rb |