开发者

Array initialization and method count increase ? What's the secret?

This Question may be weird or i am plain dumb.

>> Array.methods.count
=> 97
>> a = Array.new.methods
=> 167

W开发者_如何学Pythonhat causes the increase in number of methods after an array has been initialized and assigned.


You are counting two things: class-methods and instance methods. You may compare it with instance_methods

p Array.methods.count          #->  97
p Array.instance_methods.count #-> 167
p Array.new.methods.count      #-> 167

Or take a look if new is a valid method:

p Array.methods.include?(:new) #true
p Array.instance_methods.include?(:new) #false

new is only defined on the class, not in the instance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜