Module: IOStruct::InstanceMethods

Defined in:
lib/iostruct.rb

Overview

ClassMethods

Instance Method Summary collapse

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/iostruct.rb', line 79

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
)


88
89
90
91
92
93
94
95
96
97
# File 'lib/iostruct.rb', line 88

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



75
76
77
# File 'lib/iostruct.rb', line 75

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