Apply PIE to nghttpx
[platform/upstream/nghttp2.git] / third-party / mruby / mrbgems / mruby-range-ext / mrblib / range.rb
1 class Range
2   ##
3   # call-seq:
4   #    rng.first    -> obj
5   #    rng.first(n) -> an_array
6   #
7   # Returns the first object in the range, or an array of the first +n+
8   # elements.
9   #
10   #   (10..20).first     #=> 10
11   #   (10..20).first(3)  #=> [10, 11, 12]
12   #
13   def first(*args)
14     return self.begin if args.empty?
15
16     raise ArgumentError, "wrong number of arguments (given #{args.length}, expected 1)" unless args.length == 1
17     nv = args[0]
18     n = nv.__to_int
19     raise ArgumentError, "negative array size (or size too big)" unless 0 <= n
20     ary = []
21     each do |i|
22       break if n <= 0
23       ary.push(i)
24       n -= 1
25     end
26     ary
27   end
28 end