Wow, there's a lot in your question...
Ruby allows you to put single line if statements at the end of a line. The preceding statement is only executed if the if statement returns true. These are often used for "guard clauses". But that's not exactly what's happening here...
Ruby also lets you drop the parentheses around method calls if it can infer exactly what the parameters are. Instead of typing sum(a, b) you can type sum a, b. It's one of the things that makes Ruby great for writing "Domain Specific Languages" like Rake and parts of ActiveRecord. Thoughtbot has a good article on them.
Because of this, that line could be rewritten:
before_validation(:start_at, if: -> { status_change? && finished? })
In this case, before_validation is an ActiveRecord callback. From that link, "Callbacks are methods that get called at certain moments of an object's life cycle. With callbacks it is possible to write code that will run whenever an Active Record object is created, saved, updated, deleted, validated, or loaded from the database."
In this case what you have is a "conditional callback". The start_at method (which you'll probably find defined at the bottom of the model file, or perhaps somewhere else, search the codebase for "def start_at") only gets called if the condition passes.
Regarding the condition itself, status_change? and finished? are also both methods. The question mark at the end is a Ruby convention to say this method returns a boolean. The && is Boolean logic to say that the whole conditional will return true if and only if both status_change? and finished? return true.
So, to state what this line of code does in plain English:
- Before ActivRecord checks to see if the model is valid
- run the
start_at method...
- ...but only if the
status_change? method and finished? method both evaluate to true
Under the covers, the way this works is by passing a "lambda" as a parameter to the method. In this case it's using the "stabby lambda" syntax introduced back in Ruby 1.9. Check out The Ultimate Guide to Blocks, Procs and Lambdas and Using Lambdas in Ruby for more information.