有没有办法使用Opal的红宝石数学图书馆?
在我的ruby方法中使用Uncaught NameError: uninitialized constant Object::Math时,我得到了下面的错误消息Math::PI。
红宝石代码:
class Numeric
def degrees
self * Math::PI / 180
end
endOpal生成的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
;(谢谢;)
发布于 2015-01-13 19:24:32
Math模块在Opal的stdlib中,不包括在默认运行时(据我所知)。
根据部署上下文的不同,将Math模块(Opal::Builder.build('math'))放入文件可能是最容易的。
不过,对于您的具体示例,您可以只使用JS近似(Opal的Math::PI所做的全部工作):
class Numeric
def degrees
self * `Math.PI` / 180
end
endhttps://stackoverflow.com/questions/27929098
复制相似问题