source: EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-range-ext/mrblib/range.rb@ 331

Last change on this file since 331 was 331, checked in by coas-nagasima, 6 years ago

prototoolに関連するプロジェクトをnewlibからmuslを使うよう変更・更新
ntshellをnewlibの下位の実装から、muslのsyscallの実装に変更・更新
以下のOSSをアップデート
・mruby-1.3.0
・musl-1.1.18
・onigmo-6.1.3
・tcc-0.9.27
以下のOSSを追加
・openssl-1.1.0e
・curl-7.57.0
・zlib-1.2.11
以下のmrbgemsを追加
・iij/mruby-digest
・iij/mruby-env
・iij/mruby-errno
・iij/mruby-iijson
・iij/mruby-ipaddr
・iij/mruby-mock
・iij/mruby-require
・iij/mruby-tls-openssl

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby
File size: 936 bytes
Line 
1class 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 raise TypeError, "no implicit conversion from nil to integer" if nv.nil?
19 raise TypeError, "no implicit conversion of #{nv.class} into Integer" unless nv.respond_to?(:to_int)
20 n = nv.to_int
21 raise TypeError, "no implicit conversion of #{nv.class} into Integer" unless n.kind_of?(Integer)
22 raise ArgumentError, "negative array size (or size too big)" unless 0 <= n
23 ary = []
24 each do |i|
25 break if n <= 0
26 ary.push(i)
27 n -= 1
28 end
29 ary
30 end
31end
Note: See TracBrowser for help on using the repository browser.