source: EcnlProtoTool/trunk/mruby-1.3.0/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;charset=UTF-8
File size: 1.2 KB
Line 
1##
2# Range
3#
4# ISO 15.2.14
5class Range
6
7 ##
8 # Calls the given block for each element of +self+
9 # and pass the respective element.
10 #
11 # ISO 15.2.14.4.4
12 def each(&block)
13 return to_enum :each unless block_given?
14
15 val = self.first
16 last = self.last
17
18 if val.kind_of?(Fixnum) && last.kind_of?(Fixnum) # fixnums are special
19 lim = last
20 lim += 1 unless exclude_end?
21 i = val
22 while i < lim
23 block.call(i)
24 i += 1
25 end
26 return self
27 end
28
29 if val.kind_of?(String) && last.kind_of?(String) # fixnums are special
30 if val.respond_to? :upto
31 return val.upto(last, exclude_end?, &block)
32 else
33 str_each = true
34 end
35 end
36
37 raise TypeError, "can't iterate" unless val.respond_to? :succ
38
39 return self if (val <=> last) > 0
40
41 while (val <=> last) < 0
42 block.call(val)
43 val = val.succ
44 if str_each
45 break if val.size > last.size
46 end
47 end
48
49 block.call(val) if !exclude_end? && (val <=> last) == 0
50 self
51 end
52
53 # redefine #hash 15.3.1.3.15
54 def hash
55 h = first.hash ^ last.hash
56 h += 1 if self.exclude_end?
57 h
58 end
59end
60
61##
62# Range is enumerable
63#
64# ISO 15.2.14.3
65class Range
66 include Enumerable
67end
Note: See TracBrowser for help on using the repository browser.