作者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