我想做这样的事情.它给了我一个错误,我猜是因为它op是一个字符串.是否可以将数学运算符的字符串转换为运算符?
def calc(op)
a = 9
b = 5
a op b
end
p calc('-')
p calc('+')
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个关于jasmine的测试以检查是否readline.createInterface()已调用,但我一直收到错误消息:TypeError: readline.createInterface is not a function
这是我在游戏课中的大致内容:
run() {
let rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt: 'OHAI> '
});
rl.prompt();
// ... and the rest ...
}
Run Code Online (Sandbox Code Playgroud)
和我的测试:
describe('run', () => {
it('should create readline interface', () => {
let readline = jasmine.createSpyObj('readline', ['createInterface']);
game.run();
expect(readline.createInterface).toHaveBeenCalled();
});
});
Run Code Online (Sandbox Code Playgroud)
有人有建议吗?