Class: Array

Inherits:
Object show all
Defined in:
opal/stdlib/pp.rb,
opal/stdlib/json.rb,
opal/stdlib/await.rb,
opal/stdlib/native.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#each_await(&block) ⇒ Object



28
29
30
31
# File 'opal/stdlib/await.rb', line 28

def each_await(&block)
  map_await(&block).__await__
  self
end

#map_await(&block) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'opal/stdlib/await.rb', line 18

def map_await(&block)
  i = 0
  results = []
  while i < `self.length`
    results << yield(self[i]).__await__
    i += 1
  end
  results
end

#pretty_print(q) ⇒ Object

:nodoc:



335
336
337
338
339
340
341
# File 'opal/stdlib/pp.rb', line 335

def pretty_print(q) # :nodoc:
  q.group(1, '[', ']') {
    q.seplist(self) {|v|
      q.pp v
    }
  }
end

#pretty_print_cycle(q) ⇒ Object

:nodoc:



343
344
345
# File 'opal/stdlib/pp.rb', line 343

def pretty_print_cycle(q) # :nodoc:
  q.text(empty? ? '[]' : '[...]')
end

#to_jsonObject



134
135
136
137
138
139
140
141
142
143
144
# File 'opal/stdlib/json.rb', line 134

def to_json
  %x{
    var result = [];

    for (var i = 0, length = #{self}.length; i < length; i++) {
      result.push(#{`self[i]`.to_json});
    }

    return '[' + result.join(',') + ']';
  }
end

#to_nObject

Retuns a copy of itself trying to call #to_n on each member.



496
497
498
499
500
501
502
503
504
505
506
507
508
# File 'opal/stdlib/native.rb', line 496

def to_n
  %x{
    var result = [];

    for (var i = 0, length = self.length; i < length; i++) {
      var obj = self[i];

      result.push(#{Native.try_convert(`obj`, `obj`)});
    }

    return result;
  }
end