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



114
115
116
117
118
119
120
121
122
123
124
# File 'opal/stdlib/json.rb', line 114

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



391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
# File 'opal/stdlib/native.rb', line 391

def to_n
  %x{
    var result = [];

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

      if (#{`obj`.respond_to? :to_n}) {
        result.push(#{`obj`.to_n});
      }
      else {
        result.push(obj);
      }
    }

    return result;
  }
end