Ruby on Rails - ActiveSupport: Array Extensions -


in extensions array class (rails/activesupport/lib/active_support/core_ext/array/access.rb) following function defined:

# returns beginning of array +position+. def to(position)   if position >= 0     take position + 1   else     self[0..position]   end end 

why defined this? why can't do:

def to(position)   self[0..position] end 

according commit message of change in rails code, looks trying "avoid creating range objects".

when arr[0..3], 0..3 part becomes range object, gets used calculate subarray. i'm guessing trying save memory avoiding this.


Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -