lib/packetgen/packet.rb in packetgen-3.1.5 vs lib/packetgen/packet.rb in packetgen-3.1.6

- old
+ new

@@ -4,10 +4,12 @@ # This file is part of PacketGen # See https://github.com/sdaubert/packetgen for more informations # Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net> # This program is published under MIT license. +# rubocop:disable Metrics/ClassLength + module PacketGen # An object of type {Packet} handles a network packet. This packet may contain # multiple protocol headers, starting from MAC layer or from Network (OSI) layer. # # Creating a packet is fairly simple: @@ -75,14 +77,14 @@ # Same arguments as {Capture#initialize} # @see Capture#initialize # @yieldparam [Packet,String] packet if a block is given, yield each # captured packet (Packet or raw data String, depending on +:parse+ option) # @return [Array<Packet>] captured packet - def self.capture(**kwargs) - capture = Capture.new(kwargs) + def self.capture(**kwargs, &block) + capture = Capture.new(**kwargs) if block_given? - capture.start { |packet| yield packet } + capture.start(&block) else capture.start end capture.packets end @@ -519,8 +521,10 @@ nil end end end + +# rubocop:enable Metrics/ClassLength require_relative 'headerable' require_relative 'header'