1

Trying to get the aerospike ruby client to work under 1.8

What is the equivalent of these calls in ruby 1.8 ?

https://github.com/aerospike/aerospike-client-ruby/blob/master/lib/aerospike/utils/buffer.rb#L65

https://github.com/aerospike/aerospike-client-ruby/blob/master/lib/aerospike/utils/buffer.rb#L95

letronje
  • 9,002
  • 9
  • 45
  • 53
  • 3
    IIRC, that's `String#[]` and `String#[]=` – Stefan Dec 02 '14 at 14:06
  • Don't link to offsite code. When those links break, and they will, your question will be meaningless. Instead, extract only the important section from the linked page and put that in your question. Also, putting in the link forces potential answerers to chase down that information, which takes extra time, and in some cases prevents them from answering at all. So, it's to your advantage to put the information they need at hand. – the Tin Man Dec 02 '14 at 16:57

2 Answers2

1

IIRC, Ruby 1.8 strings are, for all intents and purposes, what 1.9 would treat as ASCII-8BIT. As such, String#[] and String#[]= are the way to proceed as already suggested in the comments. (The same functions in 1.9 will target a potentially multibyte character at a certain offset, rather than a byte.)

For a more complete discussion on Ruby M17N and how strings changed in Ruby 1.9, see:

Denis de Bernardy
  • 75,850
  • 13
  • 131
  • 154
1

Rather than rely on how a particular version of Ruby processes bytes/chars/strings, instead use the pack and unpack methods. They are always available and behave consistently.

For your use, unpack the data into an array, then you can use normal Array slicing to change the bytes in question, then pack everything back into the byte-stream.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303