添加新操作符到Ruby

Jay Phillips发布了一个叫superators的库,用来添加新操作符到Ruby中

安装
gem install superators


扩展String
require 'superators'

class String
  superator "++" do |operand|
    upcase + operand.upcase
  end
  superator "-~+~-" do |operand|
    puts "Using pretty superators"
    self + operand
  end
end


你可能感兴趣的:(Ruby)