Class: Native::Object
- Inherits:
-
BasicObject
- Includes:
- Wrapper
- Defined in:
- opal/stdlib/native.rb
Instance Method Summary
collapse
Methods included from Wrapper
included, #initialize, #to_n
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(mid, *args, &block) ⇒ Object
325
326
327
328
329
330
331
332
333
334
|
# File 'opal/stdlib/native.rb', line 325
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
256
257
258
|
# File 'opal/stdlib/native.rb', line 256
def ==(other)
`#{@native} === #{::Native.try_convert(other)}`
end
|
282
283
284
285
286
287
288
289
290
291
292
293
|
# File 'opal/stdlib/native.rb', line 282
def [](key)
%x{
var prop = #{@native}[key];
if (prop instanceof Function) {
return prop;
}
else {
return #{::Native.call(@native, key)}
}
}
end
|
#[]=(key, value) ⇒ Object
295
296
297
298
299
300
301
302
303
|
# File 'opal/stdlib/native.rb', line 295
def []=(key, value)
native = ::Native.try_convert(value)
if `#{native} === nil`
`#{@native}[key] = #{value}`
else
`#{@native}[key] = #{native}`
end
end
|
350
351
352
|
# File 'opal/stdlib/native.rb', line 350
def class
`self.$$class`
end
|
#each(*args) ⇒ Object
268
269
270
271
272
273
274
275
276
277
278
279
280
|
# File 'opal/stdlib/native.rb', line 268
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?
260
261
262
|
# File 'opal/stdlib/native.rb', line 260
def has_key?(name)
`Opal.hasOwnProperty.call(#{@native}, #{name})`
end
|
358
359
360
|
# File 'opal/stdlib/native.rb', line 358
def inspect
"#<Native:#{`String(#{@native})`}>"
end
|
#instance_of?(klass) ⇒ Boolean
346
347
348
|
# File 'opal/stdlib/native.rb', line 346
def instance_of?(klass)
`self.$$class === klass`
end
|
#is_a?(klass) ⇒ Boolean
Also known as:
kind_of?
340
341
342
|
# File 'opal/stdlib/native.rb', line 340
def is_a?(klass)
`Opal.is_a(self, klass)`
end
|
#merge!(other) ⇒ Object
305
306
307
308
309
310
311
312
313
314
315
|
# File 'opal/stdlib/native.rb', line 305
def merge!(other)
%x{
other = #{::Native.convert(other)};
for (var prop in other) {
#{@native}[prop] = other[prop];
}
}
self
end
|
336
337
338
|
# File 'opal/stdlib/native.rb', line 336
def nil?
false
end
|
#respond_to?(name, include_all = false) ⇒ Boolean
317
318
319
|
# File 'opal/stdlib/native.rb', line 317
def respond_to?(name, include_all = false)
::Kernel.instance_method(:respond_to?).bind(self).call(name, include_all)
end
|
#respond_to_missing?(name, include_all = false) ⇒ Boolean
321
322
323
|
# File 'opal/stdlib/native.rb', line 321
def respond_to_missing?(name, include_all = false)
`Opal.hasOwnProperty.call(#{@native}, #{name})`
end
|
#to_a(options = {}, &block) ⇒ Object
354
355
356
|
# File 'opal/stdlib/native.rb', line 354
def to_a(options = {}, &block)
::Native::Array.new(@native, options, &block).to_a
end
|