Class: Lycra::Attributes::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/lycra/attributes/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, attributes = {}) ⇒ Collection

Returns a new instance of Collection.



8
9
10
11
# File 'lib/lycra/attributes/collection.rb', line 8

def initialize(klass, attributes={})
  @klass = klass
  @attributes = attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/lycra/attributes/collection.rb', line 25

def method_missing(meth, *args, &block)
  if @attributes.respond_to?(meth)
    @attributes.send(meth, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



6
7
8
# File 'lib/lycra/attributes/collection.rb', line 6

def attributes
  @attributes
end

Instance Method Details

#dup(klass = nil) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/lycra/attributes/collection.rb', line 13

def dup(klass=nil)
  self.class.new(klass || @klass, attributes.map { |k,attr|
    duped = attr.dup
    duped.instance_variable_set(:@klass, klass || @klass)
    [k, duped]
  }.to_h)
end

#each(&block) ⇒ Object



21
22
23
# File 'lib/lycra/attributes/collection.rb', line 21

def each(&block)
  @attributes.each(&block)
end

#respond_to_missing?(meth, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/lycra/attributes/collection.rb', line 33

def respond_to_missing?(meth, include_private=false)
  @attributes.respond_to?(meth, include_private) || super
end