class Object

Public Instance Methods

Bool(arg) click to toggle source

Converts arg to a boolean (true or false).

# File lib/mug/bool.rb, line 5
def Bool(arg)
  !!arg
end
_?() click to toggle source

Begins a FragileMethodChain.

# File lib/mug/fragile-method-chain.rb, line 67
def _?
  FragileMethodChain.new(self)
end
and(default) { |self| ... } click to toggle source

Returns either obj or default, depending on the falsiness of obj.

If a block is given, obj is yielded to it; if it returns truthy, default is returned, otherwise obj is returned.

# File lib/mug/and-or.rb, line 10
def and default, &_block
  if block_given?
    yield(self) ? default : self
  else
    self && default
  end
end
and_then() { |self| ... } click to toggle source

Calls block if obj is truthy.

Returns obj.

# File lib/mug/and-or.rb, line 37
def and_then &_block
  yield self if self
  self
end
cede(*args, &_block)
Alias for: revapply
iff?(*condition) { || ... } click to toggle source

Test for logical equivalence.

Returns true if condition and obj are either both truthy, or both falsey.

# File lib/mug/iff.rb, line 10
def iff? *condition
  if condition.length == 1
    cond = condition[0]
  elsif condition.empty? && block_given?
    cond = yield
  else
    raise ArgumentError, "wrong number of arguments (given #{condition.length}, expected 1)"
  end
  cond ? !!self : !self
end
iter_for(meth, *args) click to toggle source

Creates a new Iterator for the method named meth

# File lib/mug/iterator/for.rb, line 8
def iter_for meth, *args
  Iterator.new(self) do |o|
    o.send(meth, *args)
  end
end
Also aliased as: to_iter
itself(&_block)
Alias for: self
maybe(&b) click to toggle source

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.

# File lib/mug/maybe.rb, line 44
def maybe &b
  if b
    self && instance_eval(&b)
  else
    MaybeDelegator.new(self)
  end
end
or(default) { |self| ... } click to toggle source

Returns either obj or default, depending on the truthiness of obj.

If a block is given, obj is yielded to it; if it returns truthy, obj is returned, otherwise default is returned.

# File lib/mug/and-or.rb, line 24
def or default, &_block
  if block_given?
    yield(self) ? self : default
  else
    self || default
  end
end
or_then() { |self| ... } click to toggle source

Calls block is obj is not falsey.

Returns obj.

# File lib/mug/and-or.rb, line 47
def or_then &_block
  yield self unless self
  self
end
revapply(*args) { |self, *args| ... } click to toggle source

Yields this object (and any other arguments) to a block. If no block is given, returns an Enumerator.

# File lib/mug/self.rb, line 29
def revapply(*args, &_block)
  if block_given?
    yield self, *args
  else
    enum_for(:revapply, *args) { args.length + 1 }
  end
end
Also aliased as: cede
self() { |self| ... } click to toggle source

Returns this object.

If a block is given, this object is yielded to it, and the result is returned.

# File lib/mug/self.rb, line 9
def self(&_block)
  if block_given?
    yield self
  else
    self
  end
end
Also aliased as: itself
to_b() click to toggle source

Converts obj to a boolean.

# File lib/mug/bool.rb, line 20
def to_b
  true
end
to_bool() click to toggle source

Converts obj to a boolean.

# File lib/mug/bool.rb, line 13
def to_bool
  true
end
to_iter(meth, *args)
Alias for: iter_for