1
A
回答
1
3
使用双冒号创建一个类的方法。
class A
def A::f
puts "Called A::f"
end
end
puts "A.public_methods:"
puts A.public_methods(false)
puts
a = A.new
puts "a.public_methods:"
puts a.public_methods(false)
puts
puts "Attempt to call f"
A.f
a.f
输出:你可以做一个简单的测试,看看这
A.public_methods:
f
allocate
new
superclass
a.public_methods:
Attempt to call f
Called A::f
NoMethodError: undefined method ‘f’ for #<A:0x0000010084f020>
相关问题
- 1. 前缀的含义是什么? Ruby 1.9中的运算符
- 2. Ruby中“$”字符的含义是什么?
- 3. 运算符| =在C#中的含义是什么?
- 4. #^运算符在Clojure中的含义是什么?
- 5. '&'在一个一元运算符中的含义是什么?
- 6. 在ABAP运算符中,=的含义是什么?
- 7. 运算符'=>'在C#中的含义是什么?
- 8. | =运算符在C++中的含义是什么?
- 9. 运算符||的含义是什么?在linux shell中?
- 10. `#`运算符在Scala中的含义是什么?
- 11. __FILE__在Ruby中的含义是什么?
- 12. * $ <在Ruby中的含义是什么?
- 13. Go中的“| =”运算符的含义是什么?
- 14. Objective C中“* =”运算符的含义是什么?
- 15. Java中'新'运算符的真正含义是什么?
- 16. asp.net.mvc中@ *运算符的含义是什么?
- 17. Underscore.js中加号运算符的含义是什么?
- 18. @运算符的意义是什么?
- 19. 模运算符的语义是什么?
- 20. Ruby中@@变量的含义是什么?
- 21. || = Ruby语言中的含义是什么?
- 22. Ruby中'<==>'的含义是什么?
- 23. Ruby中i.to_s的含义是什么?
- 24. 未定义的方法错误,但方法在Ruby中定义...为什么?
- 25. 是什么!是指在Ruby方法定义的末尾?
- 26. Ruby中的“=〜”运算符是什么?
- 27. 这些Java运算符的含义是什么?
- 28. Ruby中的百分号+管道运算符的含义如“%|”中的含义?
- 29. Application.Exit方法的含义是什么?
- 30. 什么时候在Rails中使用“|| =”运算符?它的意义是什么?
谢谢,但它似乎不可思议使用::定义一个类的方法... – Rasefon 2011-01-31 09:20:38