Module: PackedStruct

Defined in:
lib/packed_struct.rb,
lib/packed_struct/package.rb,
lib/packed_struct/version.rb,
lib/packed_struct/modifier.rb,
lib/packed_struct/directive.rb

Overview

Create structs to manage packed strings.

Defined Under Namespace

Classes: Directive, Modifier, Package, UnknownModifierError

Constant Summary collapse

VERSION =

The current version of PackedStruct.

"0.4.1".freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(reciever) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Called when this is included into another module.

Parameters:

  • reciever (Module)

    the reciever that included this one.



44
45
46
# File 'lib/packed_struct.rb', line 44

def self.included(reciever)
  reciever.extend self
end

Instance Method Details

#struct_layout(name = nil) { ... } ⇒ Package, Hash<Symbol, Package>

Define a struct. The name will be used for #structs, and the block will run in the context of a Package.

Parameters:

  • name (Symbol, nil) (defaults to: nil)

    the name of the struct. If it’s nil, it is set as the only struct of the included module.

Yields:

Returns:



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/packed_struct.rb', line 27

def struct_layout(name = nil, &block)
  structs[name] = Package.new
  structs[name].instance_exec &block
  structs[name].finalize_directives!

  if name == nil
    @structs = structs[name]
  end

  structs
end

#structsPackage, Hash<Symbol, Package> Also known as: struct

The structs that were defined on the module that included this. If the structs were defined without a name, this will be the one and only struct that was defined (or the last one that was defined).

Returns:



14
15
16
# File 'lib/packed_struct.rb', line 14

def structs
  @structs ||= {}
end