ルビーのコツ3則
581 ワード
*どうやって16進数に変換しますか?
*utf-8文字列の中国語文字はどのようにscanしますか?
*case whenでarrayをマッチングするにはどうすればいいですか?
class Integer
def to_hex
sprintf "%x", self
end
end
16.to_hex #=> 10
*utf-8文字列の中国語文字はどのようにscanしますか?
requrie 'jcode'
$KCODE = 'u'
class String
def scan_chinese
self.scan /[\340\270\200-\351\276\237]/
end
end
*case whenでarrayをマッチングするにはどうすればいいですか?
colors = %w{red green blue}
case color
when *colors
...