2
有沒有辦法在Opal中使用Ruby數學庫?Opal不能使用Ruby Math庫
我在我的ruby方法中使用Math::PI
時收到以下錯誤消息Uncaught NameError: uninitialized constant Object::Math
。
紅寶石代碼:
class Numeric
def degrees
self * Math::PI/180
end
end
生成的JavaScript通過蛋白石:
/* Generated by Opal 0.6.3 */
(function($opal) {
var self = $opal.top, $scope = $opal, nil = $opal.nil, $breaker = $opal.breaker, $slice = $opal.slice, $klass = $opal.klass;
$opal.add_stubs(['$/', '$*']);
return (function($base, $super) {
function $Numeric(){};
var self = $Numeric = $klass($base, $super, 'Numeric', $Numeric);
var def = self._proto, $scope = self._scope;
return (def.$degrees = function() {
var $a, $b, self = this;
return self['$*']((($a = ((($b = $scope.Math) == null ? $opal.cm('Math') : $b))._scope).PI == null ? $a.cm('PI') : $a.PI))['$/'](180);
}, nil) && 'degrees'
})(self, null)
})(Opal);
//# sourceMappingURL=/__opal_source_maps__/game_engine/numeric.js.map
;
感謝)
太好了!由於我使用了很多數學函數,所以我將它構建成一個文件。謝謝 !! – jazzytomato
如果有人需要將其構建到文件中,下面是從irb控制檯運行的代碼:'File.open(「math.js」,'w'){| file | file.write(Opal :: Builder.build('math'))} – jazzytomato