0

メソッドをテストするために遊んでいましたString#concat(integer)。コードは次のとおりです。

irb(main):006:0> a="hello"
=> "hello"
irb(main):008:0> a<< "world"
=> "helloworld"
irb(main):009:0> a.concat(33)
=> "helloworld!"
irb(main):010:0> a.concat(32)
=> "helloworld! "
irb(main):011:0> a.concat(31)
=> "helloworld! \x1F"
irb(main):012:0> a.concat(34)
=> "helloworld! \x1F\""
irb(main):013:0> a.concat(3)
=> "helloworld! \x1F\"\x03"
irb(main):014:0>

しかし、理解できませんでした—なぜ33値は出力を与えるのhelloworld!ですか (正しく、他の整数は与えません)?

なぜ/どのように32が出力を与えるの"helloworld! "ですか?

どのようa << "world"にして文字列を内部的に作ったのですか?

4

1 に答える 1

1

マークの ASCII コードは 33 であるhelloworld!ため、表示されます。リンク.!

于 2013-01-19T17:23:54.317 に答える