Module: BinStruct::Structable
- Defined in:
- lib/bin_struct/structable.rb
Overview
Mixin to define minimal API for a class to be embbeded as an attribute in Struct object.
Optional methods
This method may, optionally, be defined by structable types:
-
from_human
to load data from a human-readable ruby object (String, Integer,…).
Instance Method Summary collapse
-
#format_inspect ⇒ ::String
Format object when inspecting a Struct object.
-
#read(str) ⇒ self
abstract
Populate object from a binary string.
-
#sz ⇒ Integer
Size of object as binary string.
-
#to_human ⇒ ::String, Integer
abstract
Return a human-readbale object.
-
#to_s ⇒ ::String
abstract
Return object as a binary string.
-
#type_name ⇒ ::String
Get type name.
Instance Method Details
#format_inspect ⇒ ::String
Format object when inspecting a BinStruct::Struct object
60 61 62 |
# File 'lib/bin_struct/structable.rb', line 60 def format_inspect to_human end |
#read(str) ⇒ self
This method is abstract.
subclass should overload it.
Populate object from a binary string
32 33 34 |
# File 'lib/bin_struct/structable.rb', line 32 def read(str) super end |
#sz ⇒ Integer
Size of object as binary string
45 46 47 |
# File 'lib/bin_struct/structable.rb', line 45 def sz to_s.size end |
#to_human ⇒ ::String, Integer
This method is abstract.
subclass should overload it.
Return a human-readbale object
52 53 54 |
# File 'lib/bin_struct/structable.rb', line 52 def to_human super end |
#to_s ⇒ ::String
This method is abstract.
subclass should overload it.
Return object as a binary string
39 40 41 |
# File 'lib/bin_struct/structable.rb', line 39 def to_s super end |
#type_name ⇒ ::String
Get type name
21 22 23 |
# File 'lib/bin_struct/structable.rb', line 21 def type_name self.class.to_s.split('::').last end |