Class: BasicObject

Defined in:
opal/opal/corelib/basic_object.rb

Instance Method Summary collapse

Constructor Details

#initializeBasicObject

Returns a new instance of BasicObject



2
3
# File 'opal/opal/corelib/basic_object.rb', line 2

def initialize(*)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args, &block) ⇒ Object



70
71
72
73
74
# File 'opal/opal/corelib/basic_object.rb', line 70

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

Instance Method Details

#!Object



33
34
35
# File 'opal/opal/corelib/basic_object.rb', line 33

def !
  false
end

#==(other) ⇒ Object Also known as: eql?, equal?



5
6
7
# File 'opal/opal/corelib/basic_object.rb', line 5

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

#__id__Object



9
10
11
# File 'opal/opal/corelib/basic_object.rb', line 9

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

#__send__(symbol, *args, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'opal/opal/corelib/basic_object.rb', line 13

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

#instance_eval(&block) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'opal/opal/corelib/basic_object.rb', line 40

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

#instance_exec(*args, &block) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'opal/opal/corelib/basic_object.rb', line 55

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