M
M
Matvey Mamonov2016-03-01 22:57:43
ruby
Matvey Mamonov, 2016-03-01 22:57:43

What is the point of such an arrangement of colons?

Learned quite a lot about Ruby before starting to learn Rails. But in one book he missed a rather important point: he didn’t figure out the setting of colons.
One thing is clear: colons before a word denote symbols in the language. But I think I missed something about hashes somewhere. Please help me figure it out. For example, here is a piece of code:

has_many :comments
validates :title, presence: true,
                         length: { minimum: 5 }

As far as I understand, the words has_many and validates are microprograms (at least that's how it was written in one of the books), like attr_accessor and others. But what about presence: true, length: ...? Is it hash notation?
And yes, how to write it in a more obvious form, so that it becomes clearer?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
Coffin, 2016-03-01
@eucalipt

This is a new version of the hash record, according to the old it will be like this
If you try to remake it in a human-readable
way Check the title for the presence of a minimum length of 5 characters.

V
vpolotskiy, 2016-03-01
@vpolotskiy

As of ruby ​​1.9, this is the new hash syntax . Get used to it)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question