Skip to content
Browse files

Ruby 1.9-specific Marshal check

Ruby 1.9 returns 1-character strings instead of
bytes. #getbyte can be used now, but it does not
exist in 1.8...
  • Loading branch information...
1 parent 559866c commit 373ec6c2493a60136ff880afed8460534fb98ff5 @skade skade committed
Showing with 15 additions and 5 deletions.
  1. +15 −5 lib/kestrel/client/unmarshal.rb
View
20 lib/kestrel/client/unmarshal.rb
@@ -11,11 +11,21 @@ def get(key, opts = {})
response
end
end
-
- def is_marshaled?(object)
- object.to_s[0] == Marshal::MAJOR_VERSION && object.to_s[1] == Marshal::MINOR_VERSION
- rescue Exception
- false
+
+ if RUBY_VERSION.respond_to?(:getbyte)
+ def is_marshaled?(object)
+ o = object.to_s
+ o.getbyte(0) == Marshal::MAJOR_VERSION && o.getbyte(1) == Marshal::MINOR_VERSION
+ rescue Exception
+ false
+ end
+ else
+ def is_marshaled?(object)
+ o = object.to_s
+ o[0] == Marshal::MAJOR_VERSION && o[1] == Marshal::MINOR_VERSION
+ rescue Exception
+ false
+ end
end
end
end

0 comments on commit 373ec6c

Please sign in to comment.
Something went wrong with that request. Please try again.