1

This code is working on the older versions 1.8.X

 @buff1 = "12"
 @buff1[0] = 0x0b                                   
 @buff1[1] = 0x0e

I have udpated small part of code . Please have a look again. because in 1.8.6 I get "\016\v" as output and in 1.9.3 showing error TypeError: can't convert Fixnum into String

Please provide solution for 1.9.3

4

1 に答える 1

0

それはで動作しますRuby 1.9.3

p RUBY_VERSION
b = "12"
@buff1 = []
@buff1[0] = 0x0b                                   
@buff1[1] = 0x0e
p @buff1

出力:

"1.9.3"
[11, 14]

おそらくあなたは試しました:

p RUBY_VERSION
b = "12" # you missed the statement @buff1 = []
@buff1[0] = 0x0b                                   
@buff1[1] = 0x0e
p @buff1

そして、以下の出力を得ました:

"1.9.3"
C:/Documents and Settings/rakshiar/My Documents/userdata/Ruby/Scripts/test.rb:11
9:in `<main>': undefined method `[]=' for nil:NilClass (NoMethodError)

このコードがお役に立てば幸いです。

アップデート

p RUBY_VERSION
@buff1 = "12"
@buff1[0] = 0x0b.to_s  
p @buff1                               
@buff1[1] = 0x0e.to_s
p @buff1

出力:

"1.9.3"
"112"
"1142"
于 2013-03-18T14:07:19.457 に答える