我刚刚完成了Ruby Koans,使用Object.send调用方法的单元和方法上的Ruby文档都没有提供有关在send方法中使用块的任何信息.将附加到send方法的块传递给它调用的方法,还是块会丢失?
例:
foo.send(:a_method) { bar.another_method }
Run Code Online (Sandbox Code Playgroud) 以下是上下文:
function compare (value1, value2) {
if(value1 < value2) {
return -1;
} else if (value1 > value2) {
return 1;
} else {
return 0;
}
}
var values = [0, 6, 8, 5];
values.sort(compare);
alert(values); // 0,5,6,8
Run Code Online (Sandbox Code Playgroud)
确实-1返回最后一个参数?就像-1在数组中使用一样?