这些奇怪的人物是什么意思? [英] What do these weird characters mean?
问题描述
我正在阅读一本Ruby书,但没有解释以下内容:
I'm reading a Ruby book but it doesn't explain the following:
-
这是什么:
validates :name, :presence => true
-
我的意思是我知道它的作用,但是
validates
是什么?它是验证器类的方法吗?如果是这样,怎么调用它而不先提到类名?
I mean I know what it does but what's
validates
? Is it a method of the validator class? If so, how come it's called without mentioning the class name first?
:
在先前的代码中以及一般的Rails中是什么意思?
What's the meaning of :
in the previous code and in Rails on general?
在以下代码中:<%= form_for([@post, @post.comments.build]) do |f| %>
-
form_for
是对象还是过程函数?
Is
form_for
an object or a procedural function?
|f|
在<%= link_to 'Edit Post', edit_post_path(@post) %>
-
edit_post_path
方法的定义对象是谁?何时何地定义?
Who, where and when was
edit_post_path
method defined?
它属于哪个类?
推荐答案
validates
is a method, part of the validators in Rails. It is declared in (actually, included to) a superclass, that is why it does not have to be declared in the model. The:
in front of anything signifies a symbol, not a variable. Symbols are part of Ruby, somewhat similar to strings.form_for
is a method, which takes a number of parameters and a block (that is why there is ado
afterwards). The|
is part of Ruby syntax, the way you enclose code block parameters.edit_post_path
is defined by the Rails magic and the routes. It is a helper method.
我鼓励您阅读这本书有关Ruby的知识,以更熟悉符号,代码块,模块和其他使Ruby成为出色的编程语言的东西.
I encourage you to read this book about Ruby to get more familiar with symbols, code blocks, modules and other things that make Ruby a great programming language.
这篇关于这些奇怪的人物是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!