title ruby雜記事本
description ruby雜記事本
datetime 2014-12-04 08:25:28
tags ruby,tips
category coding
link ruby-tips
file 2014-12-04-082528-ruby-tips
template post
end
如何在iterate一個string的時候同時取得index與char?
用with_index即可
my_str.each_char.with_index {|char, index| p index; p char; }
字元與ASCII之間的切換
字元轉ASCII
"a".ord # 97
ASCII轉字元
97.chr # "a"
取亂數的做法
在0到9之間取一個整數亂數
rand(10) # 6
在0到1之間取一個小數亂數
rand() # 0.7651037452881309