这些奇怪的人物是什么意思? [英] What do these weird characters mean?

查看:105
本文介绍了这些奇怪的人物是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读一本Ruby书,但没有解释以下内容:

I'm reading a Ruby book but it doesn't explain the following:

  1. 这是什么: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?

它属于哪个类?

推荐答案

  1. validates是一种方法,属于
  1. 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.
  2. form_for is a method, which takes a number of parameters and a block (that is why there is a do afterwards). The | is part of Ruby syntax, the way you enclose code block parameters.
  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆