Method: BinData::Array#first
- Defined in:
- lib/bindata/array.rb
#first(n = nil) ⇒ Object
Returns the first element, or the first n
elements, of the array. If the array is empty, the first form returns nil, and the second form returns an empty array.
182 183 184 185 186 187 188 189 190 191 |
# File 'lib/bindata/array.rb', line 182 def first(n = nil) if n.nil? && empty? # explicitly return nil as arrays grow automatically nil elsif n.nil? self[0] else self[0, n] end end |