Dev
Dev

Reputation: 1073

Do I understand right condition in Ruby?

There is the following condition in Ruby:

  before_create do
    self.name = login.capitalize if name.blank?
  end

Does it mean that variable self.name will take login field with capitalized text only when field name is not empty?

Upvotes: 0

Views: 43

Answers (1)

Right the opposite. self.name will receive the value of login.capitalize when name.blank? is true.

You may read this condition exactly as if it were written in the 'traditional way`, like:

if name.empty? then
  self.name = login.capitalize
end

Upvotes: 1

Related Questions