Javascript 无法将Ruby数学库与Opal一起使用
有没有办法在Opal中使用ruby数学库 在ruby方法中使用Javascript 无法将Ruby数学库与Opal一起使用,javascript,ruby,opalrb,opal,Javascript,Ruby,Opalrb,Opal,有没有办法在Opal中使用ruby数学库 在ruby方法中使用Math::PI时,我收到以下错误消息uncaughtnamererror:uninitialized constant Object::Math ruby代码: class Numeric def degrees self * Math::PI / 180 end end Opal生成的javascript: /* Generated by Opal 0.6.3 */ (function($opal) { v
Math::PI
时,我收到以下错误消息uncaughtnamererror:uninitialized constant Object::Math
ruby代码:
class Numeric
def degrees
self * Math::PI / 180
end
end
Opal生成的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
;
谢谢;) 数学模块在Opal的
stdlib
中,不包括在默认运行时中(据我所知)
根据您的部署上下文,将数学模块(Opal::Builder.build('Math')
)构建到一个文件中可能最简单
但是,对于您的特定示例,您可以只使用JS PI近似值(这就是Opal的Math::PI
所做的一切):
伟大的因为我使用了很多数学函数,所以我把它构建到了一个文件中。谢谢如果有人需要将其构建到文件中,下面是从irb控制台运行的代码:file.open(“math.js”,w'){| file | file.write(Opal::Builder.build('math'))}
class Numeric
def degrees
self * `Math.PI` / 180
end
end