Class: Array

Inherits:
Object show all
Defined in:
/Users/elia/Code/opal-docs/opal/stdlib/json.rb,
/Users/elia/Code/opal-docs/opal/stdlib/native.rb

Instance Method Summary collapse

Instance Method Details

#to_jsonObject


122
123
124
125
126
127
128
129
130
131
132
# File '/Users/elia/Code/opal-docs/opal/stdlib/json.rb', line 122

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

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


488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
# File '/Users/elia/Code/opal-docs/opal/stdlib/native.rb', line 488

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