Permalink
Browse files

modified uuidtools for ruby1.9.

  • Loading branch information...
1 parent bca17da commit 40893768471fe15796020e9b688a705b1b7ac329 @fujibee fujibee committed May 31, 2011
Showing with 8 additions and 1 deletion.
  1. +8 −1 uuidtools.rb
View
9 uuidtools.rb
@@ -626,17 +626,24 @@ def self.random_128 #:nodoc:
def self.convert_int_to_byte_string(integer, size) #:nodoc:
byte_string = ""
+ if byte_string.respond_to?(:force_encoding)
+ byte_string.force_encoding(Encoding::ASCII_8BIT)
+ end
for i in 0..(size - 1)
byte_string << ((integer >> (((size - 1) - i) * 8)) & 0xFF)
end
return byte_string
end
def self.convert_byte_string_to_int(byte_string) #:nodoc:
+ if byte_string.respond_to?(:force_encoding)
+ byte_string.force_encoding(Encoding::ASCII_8BIT)
+ end
integer = 0
size = byte_string.size
for i in 0..(size - 1)
- integer += (byte_string[i] << (((size - 1) - i) * 8))
+ ordinal = (byte_string[i].respond_to?(:ord) ? byte_string[i].ord : byte_string[i])
+ integer += (ordinal << (((size - 1) - i) * 8))
end
return integer
end

0 comments on commit 4089376

Please sign in to comment.