Class: Float

Inherits:
Object show all
Defined in:
lib/ronin/formatting/extensions/binary/float.rb

Instance Method Summary (collapse)

Instance Method Details

- (String) pack(argument)

Packs the Float into a String.

Examples:

using Array#pack template:

0.42.pack('F')
# => =\n\xD7>"

0x42.pack(:float_be)
# => ">\xD7\n="

Parameters:

Returns:

  • (String)

    The packed float.

Raises:

See Also:

Since:

  • 0.5.0



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ronin/formatting/extensions/binary/float.rb', line 52

def pack(argument)
  case argument
  when String
    [self].pack(argument)
  else
    unless Ronin::Binary::Template::FLOAT_TYPES.include?(argument)
      raise(ArgumentError,"unsupported integer type: #{argument}")
    end

    [self].pack(Ronin::Binary::Template::TYPES[argument])
  end
end