Sha256: 7fd03f85d259b9755fdd0a05393cb654a70cbaf27a9cd0f5cbee7afc67d3619d

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

class BasicObject
  def initialize(*)
  end

  def ==(other)
    `self === other`
  end

  def __id__
    `self._id || (self._id = Opal.uid())`
  end

  def __send__(symbol, *args, &block)
    %x{
      var func = self['$' + symbol]

      if (func) {
        if (block !== nil) {
          func._p = block;
        }

        return func.apply(self, args);
      }

      if (block !== nil) {
        self.$method_missing._p = block;
      }

      return self.$method_missing.apply(self, [symbol].concat(args));
    }
  end

  alias eql? ==
  alias equal? ==

  def instance_eval(&block)
    Kernel.raise ArgumentError, "no block given" unless block

    %x{
      var block_self = block._s,
          result;

      block._s = null;
      result = block.call(self, self);
      block._s = block_self;

      return result;
    }
  end

  def instance_exec(*args, &block)
    Kernel.raise ArgumentError, "no block given" unless block

    %x{
      var block_self = block._s,
          result;

      block._s = null;
      result = block.apply(self, args);
      block._s = block_self;

      return result;
    }
  end

  def method_missing(symbol, *args, &block)
    Kernel.raise NoMethodError, "undefined method `#{symbol}' for BasicObject instance"
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
opal-0.5.5 opal/corelib/basic_object.rb
opal-0.5.4 opal/core/basic_object.rb
opal-0.5.2 opal/core/basic_object.rb