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

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -