On 10/13/06, Robert Klemme <shortcutter / googlemail.com> wrote:
> On 12.10.2006 18:10, Kalman Noel wrote:
>
> class IO
>   def geti( endian = :little )
>     str = read( [0].pack('N').length )
>     str.reverse! if endian == :little
>     str.unpack( 'N' )[0]
>   end
> end
>

Ooooo ... clever!

class IO
  SIZEOF_INT = [0].pack('N').length

  def geti( endian = :little )
    str = read( SIZEOF_INT )
    str.reverse! if endian == :little
    str.unpack( 'N' )[0]
  end
end


I'm too lazy to benchmark it today, but is reverse! faster than
reverse on strings?

Blessings,
TwP