What does :this means in Ruby on Rails?
Posted
by Marco
on Stack Overflow
See other posts from Stack Overflow
or by Marco
Published on 2010-05-10T17:17:44Z
Indexed on
2010/05/10
17:24 UTC
Read the original article
Hit count: 200
ruby
Hi,
I'm new to the Ruby and Ruby on Rails world. I've read some guides, but i've some trouble with the following syntax.
I think that the usage of :condition
syntax is used in Ruby to define a class attribute with some kind of accessor, like:
class Sample
attr_accessor :condition
end
that implicitly declares the getter and setter for the "condition" property. While i was looking at some Rails sample code, i found the following examples that i don't fully understand.
For example:
@post = Post.find(params[:id])
Why it's accessing the id
attribute with this syntax, instead of:
@post = Post.find(params[id])
Or, for example:
@posts = Post.find(:all)
Is :all
a constant here? If not, what does this code really means? If yes, why the following is not used:
@posts = Post.find(ALL)
Thanks
© Stack Overflow or respective owner