Class: ArrayFields::FieldSet
- Inherits:
-
Object
- Object
- ArrayFields::FieldSet
- Defined in:
- lib/rq/arrayfields.rb
Overview
multiton cache of fields - wraps fields and fieldpos map to save memory
Instance Attribute Summary collapse
-
#fieldpos ⇒ Object
readonly
Returns the value of attribute fieldpos.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(fields) ⇒ FieldSet
constructor
A new instance of FieldSet.
- #pos(f) ⇒ Object
Constructor Details
#initialize(fields) ⇒ FieldSet
Returns a new instance of FieldSet.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rq/arrayfields.rb', line 27 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 |
Instance Attribute Details
#fieldpos ⇒ Object (readonly)
Returns the value of attribute fieldpos.
26 27 28 |
# File 'lib/rq/arrayfields.rb', line 26 def fieldpos @fieldpos end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
25 26 27 |
# File 'lib/rq/arrayfields.rb', line 25 def fields @fields end |
Class Method Details
.init_sets ⇒ Object
18 19 20 |
# File 'lib/rq/arrayfields.rb', line 18 def init_sets @sets = {} end |
.new(fields) ⇒ Object
15 16 17 |
# File 'lib/rq/arrayfields.rb', line 15 def new fields @sets[fields] ||= super end |
Instance Method Details
#pos(f) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/rq/arrayfields.rb', line 42 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 |