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中“$”字符的含义是什么?
- 2. | =运算符在C++中的含义是什么?
- 3. 运算符| =在C#中的含义是什么?
- 4. `#`运算符在Scala中的含义是什么?
- 5. 在ABAP运算符中,=的含义是什么?
- 6. 运算符'=>'在C#中的含义是什么?
- 7. '&'在一个一元运算符中的含义是什么?
- 8. __FILE__在Ruby中的含义是什么?
- 9. asp.net.mvc中@ *运算符的含义是什么?
- 10. Underscore.js中加号运算符的含义是什么?
- 11. 模运算符的语义是什么?
- 12. @运算符的意义是什么?
- 13. Ruby中i.to_s的含义是什么?
- 14. Ruby中@@变量的含义是什么?
- 15. Ruby中'<==>'的含义是什么?
- 16. || = Ruby语言中的含义是什么?
- 17. 未定义的方法错误,但方法在Ruby中定义...为什么?
- 18. 是什么!是指在Ruby方法定义的末尾?
- 19. Ruby中的“=〜”运算符是什么?
- 20. Ruby中的百分号+管道运算符的含义如“%|”中的含义?
- 21. 这些Java运算符的含义是什么?
- 22. 什么时候在Rails中使用“|| =”运算符?它的意义是什么?
- 23. Application.Exit方法的含义是什么?
- 24. 为什么在定义函数时scala使用=运算符
- 25. 运算符〜>在Scala中的含义?
- 26. Ruby中的一元加运算符有什么意义?
- 27. “uint isWidget:1;”中的冒号(:)运算符的含义是什么?在Qt中?
- 28. “+ +”运算符的含义(不是++)
- 29. Ruby中的转义字符是什么?
- 30. 运算符优先级和关联性在c#中的含义是什么?
谢谢,但它似乎不可思议使用::定义一个类的方法... – Rasefon 2011-01-31 09:20:38