什么是“翻译”? Ruby中的关键字do [英] What is "translate" keyword do in Ruby
问题描述
简短问题:
翻译一词的含义是什么,为什么它在我的IDE中显示为特殊?
Short question:
What is 'translate' word doing and why it's colored as special in my IDE?
长期问题:
我正在执行Odin项目,而04_pig_latin Ruby和RSpec练习中的代码应如下所示:
Long question:
I am doing the Odin Project, and code in 04_pig_latin Ruby and RSpec exercise should look like this:
def translate(string)
# some code
end
根据我的规范需要通过:
Per the spec which I need to pass:
describe "#translate" do
it "translates a word beginning with a vowel" do
s = translate("apple")
expect(s).to eq("appleay")
end
end
在我的Cloud9 IDE中,translate字样显示为蓝色(例如 require
或 render
),所以我假设我不能将其用作方法名称,因此需要更改给定的RSpec测试以通过它。但是,我看到其他执行此任务的人正在将该方法命名为 translate
。没有任何问题。
我对此一无所获关键字是什么使它独特,我不知道它的真正作用,也不知道它的独特性来自Ruby还是Cloud9。
In my Cloud9 IDE the word translate is colored blue (like require
or render
), so I assume that I can't use it as a method name and will need to change the given RSpec test to pass it. However, I saw that others doing this task are naming this method translate
without any issues.
I haven't found anything about this "keyword" what could make it unique, I don't know what it's really doing, and don't know whether it's uniqueness comes from Ruby or Cloud9.
推荐答案
每个Ruby语法突出显示库通常都包含在Rails等事物中使用的常用短语。例如, belongs_to
虽然不是Ruby的特殊关键字,但在Rails应用程序中非常常见,因此通常会突出显示。
Each Ruby syntax highlighting library often includes common phrases that are used in things like Rails. For example, belongs_to
, while not a special keyword in a Ruby sense, is very common in Rails applications so it's often highlighted.
translate
可能是一个特殊的短语,并且被很多I18N库使用。
translate
might be a special phrase as well as it's used by a lot of I18N libraries.
唯一可以确定的方法是查看突出显示编辑器使用的语法规则。通常,这里有一个特殊方法名称的列表。
The only way to find out for sure is to look at the rules for syntax highlighting your editor uses. Usually there's a list of special method names in there.
这篇关于什么是“翻译”? Ruby中的关键字do的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!