I mostly use String#gsub ( http://www.ruby-doc.org/core-2.1.0/String.html#method-i-gsub ) . I am familiar with it also. But today I found Kernel#gsub ( http://www.ruby-doc.org/core-2.1.1/Kernel.html#method-i-gsub ), which I have never used it. What is the use-case of this method ?
on 2014-03-19 13:39
on 2014-04-02 23:04
I tried to explore this as below : (arup~>~)$ echo 'matz' | ruby -n -e 'puts $_.gsub(/./,"*")' **** (arup~>~)$ echo 'matz' | ruby -n -e '$_.gsub(/./,"*") ; puts $_' matz (arup~>~)$ echo 'matz' | ruby -np -e '$_.gsub(/./,"*")' matz Docs is saying - **Equivalent to $_.gsub..., except that $_ will be updated if substitution occurs.** But in my case, it seems **$_** has not been updated. The reason is `String#gsub` has been called. Not `Kernel#gsub`. See below : (arup~>~)$ echo 'matz' | ruby -n -e 'p $_.method(:gsub)' #<Method: String#gsub> What am I missing in the doc ? How to call `Kernel#gsub` ?