Class: Drydock::FancyArray

Inherits:
Array
  • Object
show all
Defined in:
lib/drydock.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fieldsObject

Returns the value of attribute fields.



13
14
15
# File 'lib/drydock.rb', line 13

def fields
  @fields
end

Instance Method Details

#add_field(n) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/drydock.rb', line 14

def add_field(n)
  @fields ||= []
  field_name = n
  eval <<-RUBY, binding, '(Drydock::FancyArray)', 1
  def #{n}
    if self.size > @fields.size && '#{n}'.to_sym == @fields.last
      self[#{@fields.size}..-1]
    else
      self[#{@fields.size}]
    end
  end
  def #{n}=(val)
    if self.size > @fields.size && '#{n}'.to_sym == @fields.last
      self[#{@fields.size}..-1] = val
    else
      self[#{@fields.size}] = val
    end
  end
  RUBY
  @fields << n
  n
end