得到“未定义的局部变量或方法"; [英] getting "undefined local variable or method"
本文介绍了得到“未定义的局部变量或方法";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想尝试在Mac终端中编译此代码
Hi I wanted to try to compile this code in mac terminal
name = "Dave"
puts "Hello #{name}"
但这给了我错误
undefined local variable or method `"Dave"' for main:Object (NameError)
我尝试使用ruby hello.rb(hello.rb是文件名)进行编译
I tried to compile by using ruby hello.rb (hello.rb is the filename)
有想法吗?
推荐答案
这些是一些可疑的引号.尝试普通的.
Those are some suspicious quotes. Try normal ones.
name = "Dave"
puts "Hello, #{name}"
在我的机器上工作.
% irb
irb(main):001:0> name = "Dave"
=> "Dave"
irb(main):002:0> puts "Hello, #{name}"
Hello, Dave
=> nil
不,您不能编译红宝石代码(在您学习的这个阶段).
And no, you can't compile ruby code (at this stage of your learning).
这篇关于得到“未定义的局部变量或方法";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文