Method: Packable::ClassMethods#read_packed
- Defined in:
- lib/packable/mixin.rb
#read_packed(io, options) ⇒ Object
Default read_packed calls either the instance method read_packed or the class method unpack_string. Choose:
-
define a class method
read_packedthat returns the newly read object -
define an instance method
read_packedwhich reads the io intoself -
define a class method
unpack_stringthat reads and returns an object from the string. In this case, options should be specified!
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/packable/mixin.rb', line 46 def read_packed(io, ) if method_defined? :read_packed mandatory = instance_method(:initialize).arity mandatory = -1-mandatory if mandatory < 0 obj = new(*[nil]*mandatory) obj.read_packed(io, ) obj else len = [:bytes] s = len ? io.read_exactly(len) : io.read unpack_string(s, ) unless s.nil? end end |