when语句无法匹配对象类型
ruby吧
全部回复
仅看楼主
level 6
不许吐槽
楼主
module AB
def a
type = self.class
case type
when Fixnum
puts 1
else
puts type
end
end
end
class Integer
include AB
end
1.a
以上代码输出:
Fixnum
直接self.class==Fixnum可以得出true,但是when却无法匹配
2014年05月12日 12点05分
1
level 6
不许吐槽
楼主
http://batsov.com/articles/2012/10/14/ruby-tip-number-3-matching-on-an-objects-class-in-a-case-expression/
解决参照
2014年05月16日 04点05分
2
level 9
sevk
直接 case self 吧
2014年05月21日 01点05分
3
不许吐槽
是的
2014年05月21日 02点05分
1