lib/bindata/delayed_io.rb in bindata-2.3.3 vs lib/bindata/delayed_io.rb in bindata-2.3.4

- old
+ new

@@ -11,11 +11,11 @@ # #write_now! methods to process an additional pass. This additional pass # must specify the abs_offset of the I/O operation. # # require 'bindata' # - # obj = BinData::DelayedIO.new(:read_abs_offset => 3, :type => :uint16be) + # obj = BinData::DelayedIO.new(read_abs_offset: 3, type: :uint16be) # obj.read("\x00\x00\x00\x11\x12") # obj #=> 0 # # obj.read_now! # obj #=> 0x1112 @@ -30,16 +30,16 @@ # automatically perform the extra passes. # # class ReversePascalString < BinData::Record # auto_call_delayed_io # - # delayed_io :str, :read_abs_offset => 0 do - # string :read_length => :len + # delayed_io :str, read_abs_offset: 0 do + # string read_length: :len # end # count_bytes_remaining :total_size - # skip :to_abs_offset => lambda { total_size - 1 } - # uint8 :len, :value => lambda { str.length } + # skip to_abs_offset: -> { total_size - 1 } + # uint8 :len, value: -> { str.length } # end # # s = ReversePascalString.read("hello\x05") # s.to_binary_s #=> "hello\x05" # @@ -117,22 +117,22 @@ end # DelayedIO objects aren't read when #read is called. # The reading is delayed until this method is called. def read_now! - raise IOError.new "read from where?" unless @read_io + raise IOError, "read from where?" unless @read_io @read_io.seekbytes(abs_offset - @read_io.offset) start_read do @type.do_read(@read_io) end end # DelayedIO objects aren't written when #write is called. # The writing is delayed until this method is called. def write_now! - raise IOError.new "write to where?" unless @write_io + raise IOError, "write to where?" unless @write_io @write_io.seekbytes(abs_offset - @write_io.offset) @type.do_write(@write_io) end end @@ -159,11 +159,11 @@ def auto_call_delayed_io include AutoCallDelayedIO DelayedIO.send(:alias_method, :initialize_instance_without_record_io, :initialize_instance) DelayedIO.send(:define_method, :initialize_instance) do - if @parent and ! defined? @delayed_io_recorded + if @parent && !defined? @delayed_io_recorded @delayed_io_recorded = true list = top_level_get(:delayed_ios) list << self if list end @@ -177,14 +177,14 @@ top_level_set(:delayed_ios, []) super end def read(io) - super(io) { top_level_get(:delayed_ios).each { |obj| obj.read_now! } } + super(io) { top_level_get(:delayed_ios).each(&:read_now!) } end - def write(io, *args) - super(io) { top_level_get(:delayed_ios).each { |obj| obj.write_now! } } + def write(io, *_) + super(io) { top_level_get(:delayed_ios).each(&:write_now!) } end def num_bytes to_binary_s.size end