Class: Array

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

Instance Method Summary collapse

Instance Method Details

#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.



491
492
493
494
495
496
497
498
499
500
501
502
503
# File 'opal/stdlib/native.rb', line 491

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