Ruby中,&:(ampersand-colon,"与号-冒号")的用法
前几日看Ruby代码,发现一个奇怪的用法,如下:
a='gsub'class << a def to_proc return Proc.new do |item, *params| p item.__send__ self, *params end endenddef method ['oh', 'hello', 'world'].each do |v| yield v, /o/, 'O' endendmethod &a#Oh#hellO#wOrld
1、http://stackoverflow.com/questions/1961030/ruby-ampersand-colon-shortcut
2、http://stackoverflow.com/questions/1217088/what-does-ampersand-colon-pretzel-colon-mean-in-ruby