class Ronin::Support::Binary::Struct::Member

Represents a member defined within a {Struct}.

Attributes

default[R]

The default value for the structure member.

@return [Object, Proc, nil]

name[R]

The name of the structure member.

@return [Symbol]

type_signature[R]

The type signature of the structure member.

@return [Symbol, (Symbol, Integer), Range(Symbol)]

Public Class Methods

new(name,type_signature, default: nil) click to toggle source

Initializes the structure member.

@param [Symbol] name

@param [Symbol, (Symbol, Integer), Range(Symbol)] type_signature

The type signature of the field.

@param [Object, Proc, nil] default

The optional default value for the structure's field.
# 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

Public Instance Methods

default_value(struct) click to toggle source

Returns a default value for the structure’s field.

@param [Struct] struct

The structure that is being initialized.

@return [Object, nil]

The new default value for the member field in the given structure.
# 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