Method: Packable::Extensions::Array#write_packed

Defined in:
lib/packable/extensions/array.rb

#write_packed(io, *how) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/packable/extensions/array.rb', line 22

def write_packed(io, *how)
  return io << self.original_pack(*how) if how.first.is_a? String
  how = [:repeat => :all] if how.empty?
  current = -1
  how.each do |options|
    repeat = options.is_a?(Hash) ? options.delete(:repeat) || 1 : 1
    repeat = length - 1 - current if repeat == :all
    repeat.times do
      io.write(self[current+=1],options)
    end
  end
end