Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/mug/bool.rb,
lib/mug/self.rb,
lib/mug/maybe.rb,
lib/mug/iterator/for.rb,
lib/mug/fragile-method-chain.rb
Instance Method Summary collapse
-
#_? ⇒ Boolean
Begins a FragileMethodChain.
-
#iter_for(meth, *args) ⇒ Object
(also: #to_iter)
Creates a new Iterator for the method named
meth. -
#maybe(&b) ⇒ Object
Do something if this object is truthy.
-
#self(&block) ⇒ Object
Returns this object.
-
#to_b ⇒ Object
Converts obj to a boolean.
-
#to_bool ⇒ Object
Converts obj to a boolean.
Instance Method Details
#_? ⇒ Boolean
Begins a FragileMethodChain.
50 51 52 |
# File 'lib/mug/fragile-method-chain.rb', line 50 def _? FragileMethodChain.new(self) end |
#iter_for(meth, *args) ⇒ Object Also known as: to_iter
Creates a new Iterator for the method named meth
8 9 10 |
# File 'lib/mug/iterator/for.rb', line 8 def iter_for meth, *args Iterator.new self, meth, *args end |
#maybe(&b) ⇒ Object
Do something if this object is truthy.
If a block is given, it is executed in the context of this object, iff this object is neither nil nor false.
If no block is given, returns a MaybeDelegator object.
35 36 37 38 39 40 41 |
# File 'lib/mug/maybe.rb', line 35 def maybe &b if b self && instance_eval(&b) else MaybeDelegator.new(self) end end |
#self(&block) ⇒ Object
Returns this object.
If a block is given, this object is yielded to it, and the result is returned.
9 10 11 12 13 14 15 |
# File 'lib/mug/self.rb', line 9 def self(&block) if block_given? yield self else self end end |
#to_b ⇒ Object
Converts obj to a boolean.
20 21 22 |
# File 'lib/mug/bool.rb', line 20 def to_b true end |
#to_bool ⇒ Object
Converts obj to a boolean.
13 14 15 |
# File 'lib/mug/bool.rb', line 13 def to_bool true end |