Sha256: 93ef2507f94b463fe635eabc6aa1a19d510b550bc4d4628a831e26318acb4f36

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

class BasicObject
  def initialize(*)
  end

  def ==(other)
    `#{self} === other`
  end

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

      if (func) {
        if (block !== nil) { args.push(block); }
        return func.apply(#{self}, args);
      }

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

  alias eql? ==
  alias equal? ==

  def instance_eval(&block)
    %x{
      if (block === nil) {
        no_block_given();
      }

      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)
    %x{
      if (block === nil) {
        no_block_given();
      }

      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

2 entries across 2 versions & 1 rubygems

Version Path
opal-0.3.41 opal/opal/basic_object.rb
opal-0.3.40 lib/assets/javascripts/opal/basic_object.rb