为什么不能在 singletonFixnumBignumFloat 类对象上定义 Symbol 方法,而 FalseClassTrueClass 可以有?

C:\>ruby -v
ruby 2.0.0p0 (2013-02-24) [i386-mingw32]

C:\>irb --simple-prompt
DL is deprecated, please use Fiddle
11111111111.class
#=> Bignum
class << 11111111111 ; end
#TypeError: can't define singleton
#        from (irb):2
#        from C:/Ruby200/bin/irb:12:in `<main>'

1111.class
#=> Fixnum
class << 1111 ; end
#TypeError: can't define singleton
#       from (irb):4
#       from C:/Ruby200/bin/irb:12:in `<main>'

11.11.class
#=> Float
class << 11.11 ; end
#TypeError: can't define singleton
#       from (irb):6
#       from C:/Ruby200/bin/irb:12:in `<main>'

:name.class
#=> Symbol
class << :name ; end
#TypeError: can't define singleton
#       from (irb):8
#       from C:/Ruby200/bin/irb:12:in `<main>'

最佳答案

正如 Ruby Docs 所说:


BignumFloatSymbol 也是如此

关于ruby - 为什么不能在 `singleton` `Fixnum` ,`Bignum` ,`Float` 类对象上定义 ,`Symbol` 方法,而 ` FalseClass` 和 `TrueClass` 可以有?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15418576/

10-13 04:51