Class: BasicObject

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

Direct Known Subclasses

Object

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



127
128
129
130
131
# File 'opal/opal/corelib/basic_object.rb', line 127

def method_missing(symbol, *args, &block)
  Kernel.raise NoMethodError.new(`self.$inspect && !self.$inspect.$$stub` ?
    "undefined method `#{symbol}' for #{inspect}:#{`self.$$class`}" :
    "undefined method `#{symbol}' for #{`self.$$class`}", symbol)
end

Instance Method Details

#!Object



39
40
41
# File 'opal/opal/corelib/basic_object.rb', line 39

def !
  false
end

#!=(other) ⇒ Object



43
44
45
# File 'opal/opal/corelib/basic_object.rb', line 43

def !=(other)
  !(self == other)
end

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



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

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

#__id__Object



15
16
17
# File 'opal/opal/corelib/basic_object.rb', line 15

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

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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'opal/opal/corelib/basic_object.rb', line 19

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

#eql?(other) ⇒ Boolean

Returns:



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

def eql?(other)
  self == other
end

#instance_eval(*args, &block) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'opal/opal/corelib/basic_object.rb', line 49

def instance_eval(*args, &block)
  if block.nil? && `!!Opal.compile`
    Kernel.raise ArgumentError, "wrong number of arguments (0 for 1..3)" unless (1..3).cover? args.size

    string, file, _lineno = *args
    compiled = Opal.compile string, file: (file || '(eval)'), eval: true
    wrapper  = `function() {return eval(compiled)}`

    block = Kernel.lambda { `wrapper.call(#{self})` }
  elsif args.size > 0
    Kernel.raise ArgumentError, "wrong number of arguments (#{args.size} for 0)"
  end

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

    block.$$s = null;

    // Need to pass $$eval so that method definitions know if this is
    // being done on a class/module. Cannot be compiler driven since
    // send(:instance_eval) needs to work.
    if (self.$$is_class || self.$$is_module) {
      self.$$eval = true;
      try {
        result = block.call(self, self);
      }
      finally {
        self.$$eval = false;
      }
    }
    else {
      result = block.call(self, self);
    }

    block.$$s = old;

    return result;
  }
end

#instance_exec(*args, &block) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'opal/opal/corelib/basic_object.rb', line 90

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

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

    block.$$s = null;

    if (self.$$is_class || self.$$is_module) {
      self.$$eval = true;
      try {
        result = block.apply(self, args);
      }
      finally {
        self.$$eval = false;
      }
    }
    else {
      result = block.apply(self, args);
    }

    block.$$s = block_self;

    return result;
  }
end

#singleton_method_addedObject



118
119
# File 'opal/opal/corelib/basic_object.rb', line 118

def singleton_method_added(*)
end

#singleton_method_removedObject



121
122
# File 'opal/opal/corelib/basic_object.rb', line 121

def singleton_method_removed(*)
end

#singleton_method_undefinedObject



124
125
# File 'opal/opal/corelib/basic_object.rb', line 124

def singleton_method_undefined(*)
end