5 # rng.first(n) -> an_array
7 # Returns the first object in the range, or an array of the first +n+
10 # (10..20).first #=> 10
11 # (10..20).first(3) #=> [10, 11, 12]
14 return self.begin if args.empty?
16 raise ArgumentError, "wrong number of arguments (given #{args.length}, expected 1)" unless args.length == 1
19 raise ArgumentError, "negative array size (or size too big)" unless 0 <= n
34 # fast path for numerics
35 if val.kind_of?(Numeric) && last.kind_of?(Numeric)
36 raise TypeError if exclude_end? && !last.kind_of?(Fixnum)
37 return nil if val > last
38 return nil if val == last && exclude_end?
41 max -= 1 if exclude_end?
45 # delegate to Enumerable
54 # fast path for numerics
55 if val.kind_of?(Numeric) && last.kind_of?(Numeric)
56 return nil if val > last
57 return nil if val == last && exclude_end?
63 # delegate to Enumerable