Sha256: bdb3fec64ab23d13af973a0edf778325d7414e7586956ede6740934784e703ff

Contents?: true

Size: 1.37 KB

Versions: 13

Compression:

Stored size: 1.37 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

  def !
    false
  end

  alias eql? ==
  alias equal? ==

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

    %x{
      var old = block.$$s,
          result;

      block.$$s = null;
      result = block.call(self, self);
      block.$$s = old;

      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, `self.$inspect && !self.$inspect.$$stub` ?
      "undefined method `#{symbol}' for #{inspect}:#{`self.$$class`}" :
      "undefined method `#{symbol}' for #{`self.$$class`}"
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
opal-0.8.1 opal/corelib/basic_object.rb
opal-0.8.1.rc1 opal/corelib/basic_object.rb
opal-0.8.0 opal/corelib/basic_object.rb
opal-0.8.0.rc3 opal/corelib/basic_object.rb
opal-0.8.0.rc2 opal/corelib/basic_object.rb
opal-0.8.0.rc1 opal/corelib/basic_object.rb
opal-0.8.0.beta1 opal/corelib/basic_object.rb
opal-0.7.2 opal/corelib/basic_object.rb
opal-0.7.1 opal/corelib/basic_object.rb
opal-0.7.0 opal/corelib/basic_object.rb
opal-0.7.0.rc1 opal/corelib/basic_object.rb
opal-0.7.0.beta3 opal/corelib/basic_object.rb
opal-0.7.0.beta2 opal/corelib/basic_object.rb