Module: Kernel
- Defined in:
- lib/mug/not.rb,
lib/mug/loop-with.rb
Instance Method Summary collapse
-
#loop_with_index(offset = 0) ⇒ Object
Repeatedly executes the block, yielding the current iteration count, which starts from
offset
. -
#loop_with_object(obj) ⇒ Object
Repeatedly executes the block, yielding an arbitrary object,
obj
. -
#not(*a, &b) ⇒ Object
Negate a predicate.
Instance Method Details
#loop_with_index(offset = 0) ⇒ Object
Repeatedly executes the block, yielding the current iteration count, which starts from offset
. If no block is given, returns a new Enumerator that includes the iteration count, starting from offset
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/mug/loop-with.rb', line 9 def loop_with_index(offset=0) return c=enum_for(:loop_with_index, offset) unless block_given? c = 0 + offset while true yield c c += 1 end rescue StopIteration ensure return c end |
#loop_with_object(obj) ⇒ Object
Repeatedly executes the block, yielding an arbitrary object, obj
.
24 25 26 27 28 29 30 31 32 |
# File 'lib/mug/loop-with.rb', line 24 def loop_with_object(obj) return obj=enum_for(:loop_with_object, obj) unless block_given? while true yield obj end rescue StopIteration ensure return obj end |
#not(*a, &b) ⇒ Object
Negate a predicate.
6 7 8 |
# File 'lib/mug/not.rb', line 6 def not(*a, &b) not a.empty? ? (b ? (yield self) : self) : __send__(*a, &b) end |