Type:
Class

BasicObject is the parent class of all classes in Ruby. It's an explicit blank class.

BasicObject can be used for creating object hierarchies independent of Ruby's object hierarchy, proxy objects like the Delegator class, or other uses where namespace pollution from Ruby's methods and classes must be avoided.

To avoid polluting BasicObject for other users an appropriately named subclass of BasicObject should be created instead of directly modifying BasicObject:

class MyObjectSystem < BasicObject
end

BasicObject does not include Kernel (for methods like puts) and BasicObject is outside of the namespace of the standard library so common classes will not be found without a using a full class path.

A variety of strategies can be used to provide useful portions of the standard library to subclasses of BasicObject. A subclass could include Kernel to obtain puts, exit, etc. A custom Kernel-like module could be created and included or delegation can be used via method_missing:

class MyObjectSystem < BasicObject
  DELEGATE = [:puts, :p]

  def method_missing(name, *args, &block)
    super unless DELEGATE.include? name
    ::Kernel.send(name, *args, &block)
  end

  def respond_to_missing?(name, include_private = false)
    DELEGATE.include?(name) or super
  end
end

Access to classes and modules from the Ruby standard library can be obtained in a BasicObject subclass by referencing the desired constant from the root like ::File or ::Enumerator. Like method_missing, const_missing can be used to delegate constant lookup to Object:

class MyObjectSystem < BasicObject
  def self.const_missing(name)
    ::Object.const_get(name)
  end
end
!

!obj â true or false Instance Public methods Boolean negate.

2015-03-30 23:46:03
equal?

obj.equal?(other) â true or false Instance Public methods Equality â At the

2015-03-31 00:02:58
instance_eval

obj.instance_eval(string [, filename [, lineno]] ) â objobj.instance_eval {| | block } â obj

2015-03-31 00:06:45
instance_exec

obj.instance_exec(arg...) {|var...| block } â obj Instance Public methods

2015-03-31 00:07:41
__id__

obj.__id__ â integerobj.object_id â integer Instance Public methods Returns

2015-03-30 23:54:56
__send__

foo.send(symbol [, args...]) â objfoo.__send__(symbol [, args...]) â obj Instance Public methods

2015-03-30 23:56:47
==

obj == other â true or false Instance Public methods Equality â At the

2015-03-30 23:53:25
!

obj != other â true or false Instance Public methods Returns true if

2015-03-30 23:49:48
new

new() Class Public methods Not documented

2015-03-30 23:45:16