Reputation: 175
I am new to ruby on rails but I am not finding the meaning of this line of code. I saw in the documentation of rails that select will build an array of objects from the database for the scope, converting them into an array and iterating through them using Array#select. Anyway I can’t understand the result of this line of code and on what it consists.
model.legal_storages.select{|storage| storage.send(document_type)==true}.last
Upvotes: 1
Views: 349
Reputation: 33420
model.legal_storages.select { |storage| storage.send(document_type) == true }.last - From the result of the last operation, select only the last element.
| | |
| | --------------------- For each element in model.legal_stores invoke
| | the method that is held by the variable document_type
| | and check if it's equal to true.
| |
| --------- Over the result of the last method,
| call select to filter those elements where
| condition in the block evaluates to true.
|
------------------- Invoke the method legal_stores in model.
Upvotes: 4