Paul Battley
3/13/2006 4:45:00 PM
Here's a simplistic solution:
broken = (1 == [1].pack('n')[0])
if broken
class String
alias_method :broken_unpack, :unpack
def unpack(spec)
return broken_unpack(spec.tr('nvNV', 'vnVN'))
end
end
class Array
alias_method :broken_pack, :pack
def pack(spec)
return broken_pack(spec.tr('nvNV', 'vnVN'))
end
end
end
p([1].pack('n'))
p([1].pack('v'))
p([1].pack('N'))
p([1].pack('V'))
Paul.