作者yjc1 (..........)
看板Ruby
标题[连结] Superators Add New Operators to Ruby
时间Fri Aug 31 23:56:33 2007
http://jicksta.com/articles/2007/08/29/superators-add-new-operators-to-ruby
非常有趣的东西.
网页上的两个例子:
class Array
superator "<---" do |operand|
self << operand.reverse
end
end
["jay"] <--- "spillihp"
与
class String
superator "++" do |operand|
upcase + operand.upcase
end
superator "-~+~-" do |operand|
puts "Using pretty superators"
self + operand
end
end
p "Tangy" ++ "Erlangy"
p "Super" -~+~- "ators"
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 211.76.240.242
1F:推 godfat:我想不到这要怎麽做﹍﹍败了 XD 翻 soruce code 中 09/01 00:11