Class: Superform::FieldCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/superform.rb

Instance Method Summary collapse

Constructor Details

#initialize(field:) ⇒ FieldCollection

Returns a new instance of FieldCollection.



234
235
236
237
238
# File 'lib/superform.rb', line 234

def initialize(field:, &)
  @field = field
  @index = 0
  each(&) if block_given?
end

Instance Method Details

#eachObject



240
241
242
243
244
# File 'lib/superform.rb', line 240

def each(&)
  values.each do |value|
    yield build_field(value: value)
  end
end

#fieldObject



246
247
248
# File 'lib/superform.rb', line 246

def field
  build_field
end

#valuesObject



250
251
252
# File 'lib/superform.rb', line 250

def values
  Array(@field.value)
end