ruby - What's happening with array.last[x]? -


मैं इस पर आया:

  a = [1, 2, 3, 4, 5, 6, 7] a.last # = & gt; 7 a.last [-1] # = & gt; 0 a.last [0] # = & gt; 1 a.last [1] # = & gt; 1 a.last [100] # = & gt; 0  

क्या कोई ये बता सकता है कि क्या हो रहा है और क्यों?

< कोड> सर # अंतिम अंतिम तत्व देता है, अर्थात 7 [] जोड़ना, बस नंबर की एनटी बिट लौटकर कॉल करता है:

  7 [0] # = & gt; 1 7 [1] # = & gt; 1 7 [2] # = & gt; 1 7 [3] # = & gt; 0 # ... 7 [100] # = & gt; 0 7.to_s (2) # = & gt; "111"  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -