module PackedStruct

Create structs to manage packed strings.

Constants

VERSION

The current version of PackedStruct.

Public Class Methods

included(reciever) click to toggle source

Called when this is included into another module.

@api private @param reciever [Module] the reciever that included this one. @return [void]

# File lib/packed_struct.rb, line 44
def self.included(reciever)
  reciever.extend self
end

Public Instance Methods

struct()
Alias for: structs
struct_layout(name = nil, &block) click to toggle source

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

@yield [] @param name [Symbol, nil] the name of the struct. If it’s nil, it

is set as the only struct of the included module.

@return (see structs)

# 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
structs() click to toggle source

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).

@return [Package, Hash<Symbol, Package>]

# File lib/packed_struct.rb, line 14
def structs
  @structs ||= {}
end
Also aliased as: struct