Class: Ronin::Support::Binary::Struct::Member

Inherits:
Object
  • Object
show all
Defined in:
lib/ronin/support/binary/struct/member.rb

Overview

Represents a member defined within a Ronin::Support::Binary::Struct.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type_signature, default: nil) ⇒ Member

Initializes the structure member.

Parameters:

  • name (Symbol)
  • type_signature (Symbol, (Symbol, Integer), Range(Symbol))

    The type signature of the field.

  • default (Object, Proc, nil) (defaults to: nil)

    The optional default value for the structure's field.



56
57
58
59
60
# File 'lib/ronin/support/binary/struct/member.rb', line 56

def initialize(name,type_signature, default: nil)
  @name           = name
  @type_signature = type_signature
  @default        = default
end

Instance Attribute Details

#defaultObject, ... (readonly)

The default value for the structure member.

Returns:

  • (Object, Proc, nil)


43
44
45
# File 'lib/ronin/support/binary/struct/member.rb', line 43

def default
  @default
end

#nameSymbol (readonly)

The name of the structure member.

Returns:

  • (Symbol)


33
34
35
# File 'lib/ronin/support/binary/struct/member.rb', line 33

def name
  @name
end

#type_signatureSymbol, ... (readonly)

The type signature of the structure member.

Returns:

  • (Symbol, (Symbol, Integer), Range(Symbol))


38
39
40
# File 'lib/ronin/support/binary/struct/member.rb', line 38

def type_signature
  @type_signature
end

Instance Method Details

#default_value(struct) ⇒ Object?

Returns a default value for the structure's field.

Parameters:

  • struct (Struct)

    The structure that is being initialized.

Returns:

  • (Object, nil)

    The new default value for the member field in the given structure.



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/ronin/support/binary/struct/member.rb', line 71

def default_value(struct)
  case @default
  when Proc
    if @default.arity == 1
      @default.call(struct)
    else
      @default.call
    end
  else
    @default.dup
  end
end