Class: Idl::StructType

Inherits:
Type
  • Object
show all
Defined in:
lib/idl/type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type_name, member_types, member_names) ⇒ StructType

Returns a new instance of StructType.

Raises:

  • (ArgumentError)


490
491
492
493
494
495
496
497
498
499
500
501
502
503
# File 'lib/idl/type.rb', line 490

def initialize(type_name, member_types, member_names)
  raise ArgumentError, "Argument 1 should be a type name" unless type_name.is_a?(String)

  raise ArgumentError, "Argument 2 should be an array of types" unless member_types.is_a?(Array)

  raise ArgumentError, "Argument 3 should be an array of names" unless member_names.is_a?(Array) && member_names.all? { |m| m.is_a?(String) }

  raise ArgumentError, "member_types and member_names must be the same size" unless member_names.size == member_types.size

  super(:struct)
  @type_name = type_name
  @member_types = member_types
  @member_names = member_names
end

Instance Attribute Details

#type_nameObject (readonly)

Returns the value of attribute type_name.



488
489
490
# File 'lib/idl/type.rb', line 488

def type_name
  @type_name
end

Instance Method Details

#cloneObject



505
506
507
# File 'lib/idl/type.rb', line 505

def clone
  StructType.new(@type_name, @member_types, @member_names)
end

#defaultObject



509
510
511
512
513
514
515
# File 'lib/idl/type.rb', line 509

def default
  hsh = {}
  @member_types.size.times do |i|
    hsh[@member_names[i]] = @member_types[i].default
  end
  hsh
end

#member?(name) ⇒ Boolean

Returns:

  • (Boolean)


517
# File 'lib/idl/type.rb', line 517

def member?(name) = @member_names.include?(name)

#member_type(member_name) ⇒ Object



519
520
521
522
523
524
# File 'lib/idl/type.rb', line 519

def member_type(member_name)
  idx = @member_names.index(member_name)
  raise "No member named '#{member_name}'" if idx.nil?

  @member_types[idx]
end