Module: IOStruct::InstanceMethods

Defined in:
lib/iostruct.rb

Overview

ClassMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#__offsetObject

Returns the value of attribute __offset.



88
89
90
# File 'lib/iostruct.rb', line 88

def __offset
  @__offset
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/iostruct.rb', line 94

def empty?
  to_a.all? { |t| t == 0 || t.nil? || t.to_s.tr("\x00", "").empty? }
end

#initialize(*args) ⇒ Object

allow initializing individual struct members by name, like:

PEdump::IMAGE_SECTION_HEADER.new(
  :VirtualSize    => 0x100,
  :VirtualAddress => 0x100000
)


103
104
105
106
107
108
109
110
111
112
# File 'lib/iostruct.rb', line 103

def initialize *args
  if args.size == 1 && args.first.is_a?(Hash)
    super()
    args.first.each do |k, v|
      send "#{k}=", v
    end
  else
    super
  end
end

#packObject



90
91
92
# File 'lib/iostruct.rb', line 90

def pack
  to_a.pack self.class.const_get('FORMAT')
end