Class: Native::Object
- Inherits:
-
BasicObject
- Includes:
- Native
- Defined in:
- opal/stdlib/native.rb
Instance Method Summary
collapse
Methods included from Native
call, convert, included, #initialize, is_a?, #to_n, try_convert
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(mid, *args, &block) ⇒ Object
237
238
239
240
241
242
243
244
245
246
|
# File 'opal/stdlib/native.rb', line 237
def method_missing(mid, *args, &block)
%x{
if (mid.charAt(mid.length - 1) === '=') {
return #{self[mid.slice(0, mid.length - 1)] = args[0]};
}
else {
return #{::Native.call(@native, mid, *args, &block)};
}
}
end
|
Instance Method Details
#==(other) ⇒ Object
168
169
170
|
# File 'opal/stdlib/native.rb', line 168
def ==(other)
`#@native === #{Native.try_convert(other)}`
end
|
194
195
196
197
198
199
200
201
202
203
204
205
|
# File 'opal/stdlib/native.rb', line 194
def [](key)
%x{
var prop = #@native[key];
if (prop instanceof Function) {
return prop;
}
else {
return #{::Native.call(@native, key)}
}
}
end
|
#[]=(key, value) ⇒ Object
207
208
209
210
211
212
213
214
215
|
# File 'opal/stdlib/native.rb', line 207
def []=(key, value)
native = Native.try_convert(value)
if `#{native} === nil`
`#@native[key] = #{value}`
else
`#@native[key] = #{native}`
end
end
|
262
263
264
|
# File 'opal/stdlib/native.rb', line 262
def class
`self._klass`
end
|
#each(*args) ⇒ Object
180
181
182
183
184
185
186
187
188
189
190
191
192
|
# File 'opal/stdlib/native.rb', line 180
def each(*args)
if block_given?
%x{
for (var key in #@native) {
#{yield `key`, `#@native[key]`}
}
}
self
else
method_missing(:each, *args)
end
end
|
#has_key?(name) ⇒ Boolean
Also known as:
key?, include?, member?
172
173
174
|
# File 'opal/stdlib/native.rb', line 172
def has_key?(name)
`$opal.hasOwnProperty.call(#@native, #{name})`
end
|
270
271
272
|
# File 'opal/stdlib/native.rb', line 270
def inspect
"#<Native:#{`String(#@native)`}>"
end
|
#instance_of?(klass) ⇒ Boolean
258
259
260
|
# File 'opal/stdlib/native.rb', line 258
def instance_of?(klass)
`self._klass === klass`
end
|
#is_a?(klass) ⇒ Boolean
Also known as:
kind_of?
252
253
254
|
# File 'opal/stdlib/native.rb', line 252
def is_a?(klass)
`$opal.is_a(self, klass)`
end
|
#merge!(other) ⇒ Object
217
218
219
220
221
222
223
224
225
226
227
|
# File 'opal/stdlib/native.rb', line 217
def merge!(other)
%x{
var other = #{Native.convert(other)};
for (var prop in other) {
#@native[prop] = other[prop];
}
}
self
end
|
248
249
250
|
# File 'opal/stdlib/native.rb', line 248
def nil?
false
end
|
#respond_to?(name, include_all = false) ⇒ Boolean
229
230
231
|
# File 'opal/stdlib/native.rb', line 229
def respond_to?(name, include_all = false)
Kernel.instance_method(:respond_to?).bind(self).call(name, include_all)
end
|
#respond_to_missing?(name) ⇒ Boolean
233
234
235
|
# File 'opal/stdlib/native.rb', line 233
def respond_to_missing?(name)
`$opal.hasOwnProperty.call(#@native, #{name})`
end
|
#to_a(options = {}, &block) ⇒ Object
266
267
268
|
# File 'opal/stdlib/native.rb', line 266
def to_a(options = {}, &block)
Native::Array.new(@native, options, &block).to_a
end
|