Ruby Regexp using gsub is there an equivalent to self keyword?

来源:互联网 发布:最美的句子知乎 编辑:程序博客网 时间:2024/05/17 06:14

String#gsub accepts an optional block. The return value of the block is used as a replacement string.

str.gsub(/[a-z]/) { |x| x.next }# => "bcd123"

Shorter version using &:next syntax:

str.gsub(/[a-z]/, &:next)# => "bcd123"
0 0
原创粉丝点击