What does it mean: does it mean Ruby on Rails?

I am new to the world of Ruby and Ruby on Rails. I read a few tutorials, but I have some problems with the following syntax. I think that using syntax is :conditionused in Ruby to define a class attribute with some kind of accessory, for example:

class Sample
  attr_accessor :condition
end

which implicitly declares getter and setter for the condition property. While I was looking at the Rails code example, I found the following examples that I do not quite understand.

For instance:

@post = Post.find(params[:id])

Why does it access the attribute idwith this syntax, and not:

@post = Post.find(params[id])


Or, for example:

@posts = Post.find(:all) 

Is there a :allconstant here ? If not, what does this code mean? If so, why is the following not used:

@posts = Post.find(ALL)

thank

+5
source share
4

Ruby. , ( ) .

- ( ) , .

, "" :all, to_s . ALL, , "", . -, attr_accessor, attr_reader ..

Ruby.

+10

:all - . - Ruby . : symbols, String Fixnum. , .to_sym, . , Fixnum, Fixnum. - , Fixnums: ( C- == strcmp)

, object_id ; object_ids , .

, , :

"all".to_sym.object_id == "all".to_sym.object_id #=> true

"all".to_sym.object_id == :all.object_id #=> true

: ( # to_s )

:all.to_s.object_id == :all.to_s.object_id #=> false

+1

Do not look at characters as a way to save memory. Look at them, indicating that the string should be immutable. 13 Ways to Look at a Symbol Ruby provides many ways to look at a symbol.

To use the metaphor: characters for multiple choice tests, lines for essay questions.

+1
source

This has nothing to do with Rails, it's just Ruby Symbols . :allis a character that is actually just a base string.

0
source

All Articles