Object
本ライブラリ用の Enumerator の雛形
オブジェクトの生成
引数パターン1 range : Range(サブクラスである When::Parts::GeometricComplexでもよい) 始点 - range.first 終点 - range.last count_limit : Integer 繰り返し回数(デフォルトは指定なし) 引数パターン2 first : When::TM::(Temporal)Position 始点 direction : :forward or :reverse :forward - 昇順 :reverse - 降順 count_limit : Integer 繰り返し回数(デフォルトは指定なし)
# File when/parts.rb, line 1155 1155: def initialize(*args) 1156: @options = self.class._options(args) 1157: @exdate = @options.delete(:exdate) 1158: @exevent = @options.delete(:exevent) 1159: _range(args) 1160: _rewind 1161: end
巻き戻す
returns : rewind された self
# File when/parts.rb, line 1064 1064: def _rewind 1065: @processed = @exdate.dup 1066: @count = 0 1067: @current = :first 1068: succ 1069: self 1070: end
ブロックを評価する
returns : rewind された self
# File when/parts.rb, line 998 998: def each 999: return self unless block_given? 1000: while (has_next?) do 1001: if @index 1002: yield(succ, @index) 1003: @index += 1 1004: elsif @object 1005: yield(succ, @object) 1006: else 1007: yield(succ) 1008: end 1009: end 1010: @index = @object = nil 1011: rewind 1012: end
次の要素があるか?
returns : Boolean true - ある false - ない
# File when/parts.rb, line 1080 1080: def has_next? 1081: return (@current != nil) 1082: end
次の要素を取り出す
returns : Object 次の要素 次の要素がない場合 rewind して、StopIteration例外を発生
# File when/parts.rb, line 1092 1092: def next 1093: return succ if has_next? 1094: rewind 1095: raise StopIteration, "Iteration Stopped" 1096: end
次の要素を取り出す
returns : Object 次の要素あり - 次の要素 次の要素なし - nil 次の要素がない場合 rewind や、StopIteration例外発生は行わない
# File when/parts.rb, line 1107 1107: def succ 1108: value = @current 1109: if (@count_limit.kind_of?(Numeric) && @count >= @count_limit) 1110: @current = nil 1111: else 1112: loop do 1113: @current = _succ 1114: break unless (@current) 1115: next if (@current == :next) 1116: @current = GeometricComplex.new(@current, @duration) if @duration 1117: next if _exclude(@current) 1118: case @direction 1119: when :reverse 1120: next if (@current > @first) 1121: @current = nil if (@last && @current < @last) 1122: break 1123: else 1124: next if (@current < @first) 1125: @current = nil if (@last && @current > @last) 1126: break 1127: end 1128: end 1129: @count += 1 1130: _exclude(@current) if (@current) 1131: end 1132: return value 1133: end
index をブロックに渡して評価する
offset : Integer index の初期値(デフォルト : 0) returns : When::Parts:Enumerator ブロックあり - rewind された self ブロックなし - copy
# File when/parts.rb, line 1024 1024: def with_index(offset=0, &block) 1025: if block_given? 1026: @index = offset||@count 1027: return each(block) 1028: else 1029: copy = _copy 1030: copy.object = nil 1031: copy.index = offset||@count 1032: return copy 1033: end 1034: end
index をブロックに渡して評価する
object : Object ブロックに渡す Object returns : When::Parts:Enumerator ブロックあり - rewind された self ブロックなし - copy
# File when/parts.rb, line 1046 1046: def with_object(object, &block) 1047: if block_given? 1048: @object = object 1049: each(block) 1050: return object 1051: else 1052: copy = _copy 1053: copy.object = object 1054: copy.index = nil 1055: return copy 1056: end 1057: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.