rand
Desc: 如何在自动生成一个简单的Range范围的随机数
Code:
rand(10) + 10
rand(10...20)
Random.new.rand(10...20)
awesoome_print
Desc: 能格式化JSON,HASH的输出
Code:
gem install awesome_print
require 'ap'
ap [1,2,3]
ap [1,2,3].inject({}) { |x, y| x[y.to_s] = y; x }
String
Desc: 如何simple或者sub string?
Code:
str = "this is a test"
str["test"] # will return "test"
str["yyy"] # will return nil