レシピブック:022, 024, 025

文字コード難しい問題。

[1] pry(main)> require 'nkf'
=> true
[2] pry(main)> NKF.guess("パリジェンヌ")
=> #
[3] pry(main)> exit 0

使い道を教えて下さい。

[1] pry(main)> str = "this is a string"
=> "this is a string"
[2] pry(main)> p str
"this is a string"
=> "this is a string"
[3] pry(main)> p str.dup
"this is a string"
=> "this is a string"
[4] pry(main)> p str.object
NoMethodError: undefined method `object' for "this is a string":String
from (pry):4:in `__pry__'
[5] pry(main)> p str.object_id
25765896
=> 25765896
[6] pry(main)> dupp = str.dup
=> "this is a string"
[7] pry(main)> p dupp.object_id
33028872
=> 33028872
[8] pry(main)> p str.object_id
25765896
=> 25765896
[9] pry(main)> cloned = str.clone
=> "this is a string"

文字の反復

[14] pry(main)> print "poada"
poada=> nil
[15] pry(main)> print "poada" * 5
poadapoadapoadapoadapoada=> nil
[16] pry(main)> print "poada" / 5
NoMethodError: undefined method `/' for "poada":String
from (pry):16:in `__pry__'
[17] pry(main)> print "panda " + "copanda"
panda copanda=> nil
[18] pry(main)> print ("panda " + "copanda") * 3
panda copandapanda copandapanda copanda=> nil

やってみればできるものやね。

Pocket

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です