Parent

ArrayFields::FieldSet

multiton cache of fields - wraps fields and fieldpos map to save memory

Attributes

fieldpos[R]
fields[R]

Public Class Methods

init_sets() click to toggle source
# File lib/arrayfields.rb, line 27
def init_sets
  @sets = {}
end
new(fields) click to toggle source
# File lib/arrayfields.rb, line 24
def new fields
  @sets[fields] ||= super
end
new(fields) click to toggle source
# File lib/arrayfields.rb, line 36
def initialize fields
  raise ArgumentError, "<#{ fields.inspect }> not inject-able" unless
    fields.respond_to? :inject

  @fieldpos =
    fields.inject({}) do |h, f|
      unless String === f or Symbol === f
        raise ArgumentError, "<#{ f.inspect }> neither String nor Symbol"
      end
      h[f] = h.size
      h
    end

  @fields = fields
end

Public Instance Methods

pos(f) click to toggle source
# File lib/arrayfields.rb, line 51
def pos f
  return @fieldpos[f] if @fieldpos.has_key? f 
  f = f.to_s
  return @fieldpos[f] if @fieldpos.has_key? f 
  f = f.intern
  return @fieldpos[f] if @fieldpos.has_key? f 
  nil
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.