I understand that this line will look into all items, check if the product in each item is the same as the 'product' local variable and probably will set a boolean in current_item for the result(is that right?)
so, does the |item| part means the temporary name of each object?
I understand that this line will look into all items, check if the product in each item is the same as the 'product' local variable and probably will set a boolean in current_item for the result(is that right?)
Not; it will set current_item to the item where item.product == product.
This depends on the type of @items; it might also return a collection of all items where item.product == product.
so, does the |item| part means the temporary name of each object?
Yes. Basically the find method takes a block (closure). The variable between the pipes/vertical bars is each object during the iteration. This block compares product with each item's product.
You'd be well-served to make sure you understand some Ruby basics before moving much further--otherwise RoR is indistinguishable from magic.
I understand that this line will look into all items, check if the product in each item is the same as the 'product' local variable and probably will set a boolean in current_item for the result(is that right?)
Not; it will set current_item to the item where item.product == product.
This depends on the type of @items; it might also return a collection of all items where item.product == product.
so, does the |item| part means the temporary name of each object?
Yes. Basically the find method takes a block (closure). The variable between the pipes/vertical bars is each object during the iteration. This block compares product with each item's product.
You'd be well-served to make sure you understand some Ruby basics before moving much further--otherwise RoR is indistinguishable from magic.
Thanks friend
yeah I understand that, well, I must admit Im not THAT good of a learner(as of going deep into ruby before rails ), I just read the ruby language basics appendix and I'm catching up to the language as the examples go... I hope it doesnt hold me much when I start on my own projects... heheh there's always the internet, anyway moose saloon rocks...
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12612
posted
0
For the basics, a general understanding of Ruby is enough. When things go wrong, or you want some more advanced functionality, a good grounding in Ruby is essential.