In Ruby, why does `Array.length` give NoMethodError?

ساخت وبلاگ
In Python, I can get the length of a rundown by calling its __len__ strategy. __len__ isn't characterized on every individual rundown protest, however on the rundown class. The technique can be gotten to straightforwardly through the class:

>>> [].__len__()

0

>>> type([])

<class 'list'>

>>> list.__len__([])

0

Be that as it may, the comparable code does not work in Ruby:

> [].length

=> 0

> [].class

=> Array

> Array.length([])

NoMethodError: vague strategy `length' for Array:Class

For what reason can the length strategy not be discovered when utilizing Array.length? Does strategy query in Ruby work uniquely in contrast to Python?
CodingForums...
ما را در سایت CodingForums دنبال می کنید

برچسب : نویسنده : codingforums بازدید : 182 تاريخ : پنجشنبه 30 آذر 1396 ساعت: 23:15