Module: IOStruct::ClassMethods
- Defined in:
- lib/iostruct.rb
Instance Method Summary collapse
-
#read(src, size = nil) ⇒ Object
src can be IO or String, or anything that responds to :read or :unpack.
- #size ⇒ Object
Instance Method Details
#read(src, size = nil) ⇒ Object
src can be IO or String, or anything that responds to :read or :unpack
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/iostruct.rb', line 67 def read(src, size = nil) pos = nil size ||= const_get 'SIZE' data = if src.respond_to?(:read) pos = src.tell src.read(size).to_s elsif src.respond_to?(:unpack) src else raise "[?] don't know how to read from #{src.inspect}" end new(*data.unpack(const_get('FORMAT'))).tap { |x| x.__offset = pos } end |
#size ⇒ Object
82 83 84 |
# File 'lib/iostruct.rb', line 82 def size self::SIZE end |