Skip to content

Commit

Permalink
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 9 additions & 0 deletions corelib/runtime.js
Original file line number Diff line number Diff line change
@@ -330,6 +330,15 @@
return block.apply(null, args);
};

// Helper to convert the given object to an array
Opal.to_ary = function(value) {
if (value._isArray) {
return value;
}

return [value];
};

/*
Call a ruby method on a ruby object with some arguments:
3 changes: 1 addition & 2 deletions lib/opal/parser.rb
Original file line number Diff line number Diff line change
@@ -1479,8 +1479,7 @@ def process_masgn(sexp, level)
len = rhs.length - 1 # we are guaranteed an array of this length
code << f("#{tmp} = ", sexp) << process(rhs)
elsif rhs[0] == :to_ary
code << f("((#{tmp} = ", sexp) << process(rhs[1])
code << f(")._isArray ? #{tmp} : (#{tmp} = [#{tmp}]))", sexp)
code << [f("#{tmp} = $opal.to_ary("), process(rhs[1]), f(")")]
elsif rhs[0] == :splat
code << f("(#{tmp} = ", sexp) << process(rhs[1])
code << f(")['$to_a'] ? (#{tmp} = #{tmp}['$to_a']()) : (#{tmp})._isArray ? #{tmp} : (#{tmp} = [#{tmp}])", sexp)

0 comments on commit ba7ea76

Please sign in to comment.