Class: BasicObject
- Defined in:
- opal/opal/corelib/basic_object.rb,
opal/opal/corelib/marshal/write_buffer.rb
Overview
use_strict: true
Direct Known Subclasses
Instance Method Summary collapse
- #! ⇒ Object
- #!=(other) ⇒ Object
- #==(other) ⇒ Object (also: #equal?)
- #__id__ ⇒ Object
- #__marshal__(buffer) ⇒ Object
- #__send__(symbol, *args, &block) ⇒ Object
- #eql?(other) ⇒ Boolean
-
#initialize ⇒ BasicObject
constructor
A new instance of BasicObject.
- #instance_eval(*args, &block) ⇒ Object
- #instance_exec(*args, &block) ⇒ Object
- #method_missing(symbol, *args, &block) ⇒ Object
- #respond_to_missing?(method_name, include_all = false) ⇒ Boolean
- #singleton_method_added ⇒ Object
- #singleton_method_removed ⇒ Object
- #singleton_method_undefined ⇒ Object
Constructor Details
#initialize ⇒ BasicObject
Returns a new instance of BasicObject.
4 5 |
# File 'opal/opal/corelib/basic_object.rb', line 4 def initialize(*) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &block) ⇒ Object
143 144 145 146 147 148 |
# File 'opal/opal/corelib/basic_object.rb', line 143 def method_missing(symbol, *args, &block) inspect_result = ::Opal.inspect(self) ::Kernel.raise ::NoMethodError.new( "undefined method `#{symbol}' for #{inspect_result}", symbol, args ), nil, ::Kernel.caller(1) end |
Instance Method Details
#! ⇒ Object
51 52 53 |
# File 'opal/opal/corelib/basic_object.rb', line 51 def ! false end |
#!=(other) ⇒ Object
56 57 58 |
# File 'opal/opal/corelib/basic_object.rb', line 56 def !=(other) !(self == other) end |
#==(other) ⇒ Object Also known as: equal?
7 8 9 |
# File 'opal/opal/corelib/basic_object.rb', line 7 def ==(other) `self === other` end |
#__id__ ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'opal/opal/corelib/basic_object.rb', line 17 def __id__ %x{ if (self.$$id != null) { return self.$$id; } Opal.prop(self, '$$id', Opal.uid()); return self.$$id; } end |
#__marshal__(buffer) ⇒ Object
141 142 143 144 145 146 |
# File 'opal/opal/corelib/marshal/write_buffer.rb', line 141 def __marshal__(buffer) buffer.save_link(self) buffer.write_extends(self) buffer.append('o') buffer.write_object(self) end |
#__send__(symbol, *args, &block) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'opal/opal/corelib/basic_object.rb', line 27 def __send__(symbol, *args, &block) %x{ if (!symbol.$$is_string) { #{raise ::TypeError, "#{inspect} is not a symbol nor a string"} } var func = self[Opal.jsid(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
11 12 13 |
# File 'opal/opal/corelib/basic_object.rb', line 11 def eql?(other) self == other end |
#instance_eval(*args, &block) ⇒ Object
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'opal/opal/corelib/basic_object.rb', line 60 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 = { file: (file || '(eval)'), eval: true } = __OPAL_COMPILER_CONFIG__.merge() compiled = ::Opal.compile string, block = ::Kernel.proc do %x{new Function("Opal,self", "return " + compiled)(Opal, self)} end elsif block.nil? && args.length >= 1 && args.first[0] == '@' # get instance variable return instance_variable_get(args.first) elsif args.any? ::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_a_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
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'opal/opal/corelib/basic_object.rb', line 106 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_a_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 |
#respond_to_missing?(method_name, include_all = false) ⇒ Boolean
152 153 154 |
# File 'opal/opal/corelib/basic_object.rb', line 152 def respond_to_missing?(method_name, include_all = false) false end |
#singleton_method_added ⇒ Object
134 135 |
# File 'opal/opal/corelib/basic_object.rb', line 134 def singleton_method_added(*) end |
#singleton_method_removed ⇒ Object
137 138 |
# File 'opal/opal/corelib/basic_object.rb', line 137 def singleton_method_removed(*) end |
#singleton_method_undefined ⇒ Object
140 141 |
# File 'opal/opal/corelib/basic_object.rb', line 140 def singleton_method_undefined(*) end |