Class: PacketGen::Types::String
- Inherits:
-
String
- Object
- String
- PacketGen::Types::String
- Defined in:
- lib/packetgen/types/string.rb
Overview
This class is just like regular String. It only adds #read and #sz methods to be compatible with others PacketGen::Types.
Instance Method Summary collapse
-
#initialize(str = '', options = {}) ⇒ String
constructor
A new instance of String.
-
#read(str) ⇒ String
Self.
Constructor Details
#initialize(str = '', options = {}) ⇒ String
Returns a new instance of String.
19 20 21 22 |
# File 'lib/packetgen/types/string.rb', line 19 def initialize(str='', ={}) super(str) @length_from = [:length_from] end |
Instance Method Details
#read(str) ⇒ String
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/packetgen/types/string.rb', line 26 def read(str) s = str.to_s s = case @length_from when Int s[0, @length_from.to_i] else s end self.replace s self end |