【发布时间】:2014-04-11 08:50:32
【问题描述】:
当类和语句封装在模块中时,为什么会抛出错误??
module Xchange
class Float
def in currency
self.to_s << " " << suffix(currency)
end
private
def suffix currency
case currency
when :euro
"euros"
when :dollar
"dollars"
when :rupee
"rupees"
end
end
end
puts 2.3.in(:euro)
end
【问题讨论】:
-
你使用的是什么版本的 Ruby?
标签: ruby monkeypatching