Since Ruby is very dynamic, methods added to the ancestors of BasicObject after BasicObject is defined will show up in the list of available BasicObject methods. We handle this by defining hooks in Object, Kernel and Module that will hide any defined.

Methods
Constants
ASSOCIATIONS = Hash.new{ |h,k,v| h[k]=[] }
Public Instance methods
>>(to)

Define an association with self.

# File lib/facets/more/association.rb, line 110
  def >>(to)
    ASSOCIATIONS[self] << to
    Association.new(self, to)
  end
associations()
# File lib/facets/more/association.rb, line 115
  def associations
    ASSOCIATIONS[self]
  end
bitmask(bit)
# File lib/facets/more/bitmask.rb, line 66
  def bitmask(bit)
    1 << bit
  end
demand( promise )

Forces the result of a promise to be computed (if necessary) and returns the bare result object. Once evaluated, the result of the promise will be cached. Nested promises will be evaluated together, until the first non-promise result.

If called on a value that is not a promise, it will simply return it.

# File lib/facets/more/lazy.rb, line 219
  def demand( promise )
    if promise.respond_to? :__result__
      promise.__result__
    else # not really a promise
      promise
    end
  end
future( ) {|result| ...}

Schedules a computation to be run asynchronously in a background thread and returns a promise for its result. An attempt to demand the result of the promise will block until the computation finishes.

As with Kernel.promise, this passes the block a promise for its own result. Use wisely.

# File lib/facets/more/lazy.rb, line 234
  def future( &computation ) #:yields: result
    Lazy::Future.new &computation
  end
j(*objs)

Outputs objs to STDOUT as JSON strings in the shortest form, that is in one line.

# File lib/facets/more/json.rb, line 644
  def j(*objs)
    objs.each do |obj|
      puts JSON::unparse(obj)
    end
    nil
  end
jj(*objs)

Ouputs objs to STDOUT as JSON strings in a pretty format, with indentation and over many lines.

# File lib/facets/more/json.rb, line 653
  def jj(*objs)
    objs.each do |obj|
      puts JSON::pretty_unparse(obj)
    end
    nil
  end
nack(err=nil, *data, &ctrl)
# File lib/facets/more/nackclass.rb, line 104
  def nack(err=nil, *data, &ctrl)
    NackClass.new(err, *data, &ctrl)
  end
null()
# File lib/facets/more/nullclass.rb, line 46
  def null
    NullClass.new
  end
promise( ) {|result| ...}

The promise() function is used together with demand() to implement lazy evaluation. It returns a promise to evaluate the provided block at a future time. Evaluation can be demanded and the block’s result obtained via the demand() function.

Implicit evaluation is also supported: the first message sent to it will demand evaluation, after which that message and any subsequent messages will be forwarded to the result object.

As an aid to circular programming, the block will be passed a promise for its own result when it is evaluated. Be careful not to force that promise during the computation, lest the computation diverge.

# File lib/facets/more/lazy.rb, line 208
  def promise( &computation ) #:yields: result
    Lazy::Promise.new &computation
  end
ref(x)

Shortcut reference constructor.

# File lib/facets/more/reference.rb, line 65
  def ref(x)
    Reference.new(x)
  end
timed() {|timer = Timer.new.start| ...}

Takes a block and returns the total time it took to execute.

# File lib/facets/more/timer.rb, line 235
  def timed
    yield( timer = Timer.new.start )
    return timer.total_time
  end