Module: MemoryIO::Types

Defined in:
lib/memory_io/types/types.rb,
lib/memory_io/types/type.rb,
lib/memory_io/types/c_str.rb,
lib/memory_io/types/number.rb

Overview

Module that includes multiple types.

Supported types are all descendants of Type.

Defined Under Namespace

Classes: CStr, Number, Type

Class Method Summary collapse

Class Method Details

.find(name) ⇒ Symbol, Class?

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.

Returns the class whose name matches name.

This method would search all descendants of Type.

Examples:

Types.find(:u64)
#=> MemoryIO::Types::U64

Types.find(:c_str)
#=> MemoryIO::Types::CStr

Returns:

  • (Symbol)

    name Class name to be searched.

  • (Class?)

    The class.



32
33
34
# File 'lib/memory_io/types/types.rb', line 32

def find(name)
  Types::Type.find(Util.underscore(name.to_s).to_sym)
end

.get_proc(name, rw) ⇒ Proc?

Returns a callable object according to name.

Examples:

Types.get_proc(:c_str, :write)
#=> #<Method: MemoryIO::Types::CStr.write>
Types.get_proc(:s32, :read)
#=> #<Method: MemoryIO::Types::Number#read>

Parameters:

  • name (Symbol)

    The name of type.

  • rw (:read, :write)

    Read or write?

Returns:

  • (Proc?)

    The proc that accepts stream as the first parameter.



51
52
53
54
# File 'lib/memory_io/types/types.rb', line 51

def get_proc(name, rw)
  klass = find(name)
  klass && klass.method(rw)
end