網頁

2011年3月25日 星期五

Ruby19 encoding issues

ruby1.9 encoding issues

To upgrade without any errors you should add this line at the top of all your ruby scripts:

# encoding: utf-8

otherwise it’ll throw SyntaxErrors: “invalid multibtyte char (US-ASCII)”

Also you should use mysql2 gem (or new versions of pg and sqlite-ruby) in your application, otherwise you’ll see:

Encoding::CompatibilityError: incompatible character encoding: UTF-8 and ASCII-8BIT

from:http://def-end.com/post/3065938198/ruby1-9-encoding-issues

Ruby執行系統指令

如果是要直接呼叫系統指令,底下有幾種方式可以呼叫系統指令

`` # 就是在鍵盤上"ㄅ"左邊那個按鍵,通常跟"~"印在一起
%x() # 括號也可以用雙引號代替,像是%x""或者%x!!
exec # 透過exec來執行系統指令的話,會在執行結束後一併結束Ruby
system # 用法跟exec一樣,但是結束指令時並不會一併結束Ruby

來源:http://ithelp.ithome.com.tw/question/10000145