What is “translate” keyword do in Ruby

蹲街弑〆低调 提交于 2019-12-25 08:22:49

问题


Short question:
What is 'translate' word doing and why it's colored as special in my IDE?

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

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.

Link to exercises repo


回答1:


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 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.



来源:https://stackoverflow.com/questions/41577814/what-is-translate-keyword-do-in-ruby

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!