[Ruby] sub 和 gsub 的差別

The g stands for global, as in replace globally (all):

In irb:

>> "hello".sub('l', '*')
=> "he*lo"
>> "hello".gsub('l', '*')
=> "he**o"

>> "hello".gsub "l", "*"
=> "he**o"