Class: Native::Array
- Includes:
- Enumerable, Wrapper
- Defined in:
- opal/stdlib/native.rb
Instance Method Summary collapse
- #[](index) ⇒ Object
- #[]=(index, value) ⇒ Object
- #each(&block) ⇒ Object
- 
  
    
      #initialize(native, options = {}, &block)  ⇒ Array 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Array. 
- #inspect ⇒ Object
- #last(count = nil) ⇒ Object
- #length ⇒ Object
Methods included from Enumerable
Methods included from Wrapper
Constructor Details
#initialize(native, options = {}, &block) ⇒ Array
Returns a new instance of Array.
| 367 368 369 370 371 372 373 374 375 376 377 378 379 | # File 'opal/stdlib/native.rb', line 367 def initialize(native, = {}, &block) super(native) @get = [:get] || [:access] @named = [:named] @set = [:set] || [:access] @length = [:length] || :length @block = block if `#{length} == null` raise ArgumentError, 'no length found on the array-like object' end end | 
Instance Method Details
#[](index) ⇒ Object
| 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | # File 'opal/stdlib/native.rb', line 393 def [](index) result = case index when String, Symbol @named ? `#{@native}[#{@named}](#{index})` : `#{@native}[#{index}]` when Integer @get ? `#{@native}[#{@get}](#{index})` : `#{@native}[#{index}]` end if result if @block @block.call(result) else Native(result) end end end | 
#[]=(index, value) ⇒ Object
| 410 411 412 413 414 415 416 | # File 'opal/stdlib/native.rb', line 410 def []=(index, value) if @set `#{@native}[#{@set}](#{index}, #{Native.convert(value)})` else `#{@native}[#{index}] = #{Native.convert(value)}` end end | 
#each(&block) ⇒ Object
| 381 382 383 384 385 386 387 388 389 390 391 | # File 'opal/stdlib/native.rb', line 381 def each(&block) return enum_for :each unless block %x{ for (var i = 0, length = #{length}; i < length; i++) { Opal.yield1(block, #{self[`i`]}); } } self end | 
#inspect ⇒ Object
| 440 441 442 | # File 'opal/stdlib/native.rb', line 440 def inspect to_a.inspect end | 
#last(count = nil) ⇒ Object
| 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 | # File 'opal/stdlib/native.rb', line 418 def last(count = nil) if count index = length - 1 result = [] while index >= 0 result << self[index] index -= 1 end result else self[length - 1] end end | 
#length ⇒ Object
| 434 435 436 | # File 'opal/stdlib/native.rb', line 434 def length `#{@native}[#{@length}]` end |