Module: Cel::CollectionTypeFetch

Included in:
Cel
Defined in:
lib/cel/ast/types.rb

Instance Method Summary collapse

Instance Method Details

#[](*args) ⇒ Object



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/cel/ast/types.rb', line 270

def [](*args)
  col_type, elem_type = args

  return super unless COLTYPES.include?(col_type)

  return super if args.size > 2

  elem_type ||= :any

  type = case col_type
         when :list
           ListType.new([])
         when :map
           MapType.new({})
  end

  type.element_type = elem_type.is_a?(Type) || (elem_type.is_a?(Class) && elem_type < Protobuf.base_class) ?
                      elem_type :
                      super(*elem_type)
  type
end