Sha256: b18abecf3fd8f3a087dec2848c43ec0cc828a4d65775705fb81c0d02f64b8f39
Contents?: true
Size: 1.76 KB
Versions: 3
Compression:
Stored size: 1.76 KB
Contents
# # Copyright (c) 2006-2012 Hal Brodigan (postmodern.mod3 at gmail.com) # # This file is part of Ronin Support. # # Ronin Support is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published # by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ronin Support is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with Ronin Support. If not, see <http://www.gnu.org/licenses/>. # require 'ronin/binary/template' class Float # # Packs the Float into a String. # # @param [String, Symbol] argument # The `Array#pack` String code or {Ronin::Binary::Template} type. # # @return [String] # The packed float. # # @raise [ArgumentError] # The argument was not a String code or a Symbol. # # @example using `Array#pack` template: # 0.42.pack('F') # # => =\n\xD7>" # # @example using {Ronin::Binary::Template} types: # 0x42.pack(:float_be) # # => ">\xD7\n=" # # @see http://rubydoc.info/stdlib/core/Array:pack # # @since 0.5.0 # # @api public # def pack(argument) case argument when String [self].pack(argument) when Symbol unless Ronin::Binary::Template::FLOAT_TYPES.include?(argument) raise(ArgumentError,"unsupported integer type: #{argument}") end [self].pack(Ronin::Binary::Template::TYPES[argument]) else raise(ArgumentError,"argument must be a String or a Symbol") end end end
Version data entries
3 entries across 3 versions & 1 rubygems