[フレーム]

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? , proc , #to_n , try_convert

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

319
320
321
322
323
324
325
326
327
328
# File 'opal/stdlib/native.rb', line 319
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

250
251
252
# File 'opal/stdlib/native.rb', line 250
def ==(other)
 `#@native === #{::Native .try_convert (other)}`
end

#[](key) ⇒ Object

276
277
278
279
280
281
282
283
284
285
286
287
# File 'opal/stdlib/native.rb', line 276
def [](key)
 %x{
 var prop = #@native[key];
 if (prop instanceof Function) {
 return prop;
 }
 else {
 return #{::Native .call (@native, key)}
 }
 }
end

#[]=(key, value) ⇒ Object

289
290
291
292
293
294
295
296
297
# File 'opal/stdlib/native.rb', line 289
def []=(key, value)
 native = ::Native .try_convert (value)
 if `#{native} === nil`
 `#@native[key] = #{value}`
 else
 `#@native[key] = #{native}`
 end
end

#classObject

344
345
346
# File 'opal/stdlib/native.rb', line 344
def class
 `self.$$class`
end

#each(*args) ⇒ Object

262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'opal/stdlib/native.rb', line 262
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?

Returns:

254
255
256
# File 'opal/stdlib/native.rb', line 254
def has_key?(name)
 `Opal.hasOwnProperty.call(#@native, #{name})`
end

#inspectObject

352
353
354
# File 'opal/stdlib/native.rb', line 352
def inspect
 "#<Native:#{`String(#@native)`}>"
end

#instance_of?(klass) ⇒ Boolean

Returns:

340
341
342
# File 'opal/stdlib/native.rb', line 340
def instance_of?(klass)
 `self.$$class === klass`
end

#is_a?(klass) ⇒ Boolean Also known as: kind_of?

Returns:

334
335
336
# File 'opal/stdlib/native.rb', line 334
def is_a?(klass)
 `Opal.is_a(self, klass)`
end

#merge!(other) ⇒ Object

299
300
301
302
303
304
305
306
307
308
309
# File 'opal/stdlib/native.rb', line 299
def merge!(other)
 %x{
 other = #{::Native .convert (other)};
 for (var prop in other) {
 #@native[prop] = other[prop];
 }
 }
 self
end

#nil?Boolean

Returns:

330
331
332
# File 'opal/stdlib/native.rb', line 330
def nil?
 false
end

#respond_to?(name, include_all = false) ⇒ Boolean

Returns:

311
312
313
# File 'opal/stdlib/native.rb', line 311
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

Returns:

315
316
317
# File 'opal/stdlib/native.rb', line 315
def respond_to_missing?(name, include_all = false)
 `Opal.hasOwnProperty.call(#@native, #{name})`
end

#to_a(options = {}, &block) ⇒ Object

348
349
350
# File 'opal/stdlib/native.rb', line 348
def to_a(options = {}, &block)
 ::Native ::Array .new (@native, options, &block).to_a
end

AltStyle によって変換されたページ (->オリジナル) /