In the university, a book is often placed in the course seat the night before, indicating that the position has been occupied. The next day, I came to this seat and opened the book for formal classes. in this phenomenon, Books Act as placeholders.
In Ruby, yield is a placeholder. First, yield is used in a part of the previous code to occupy the position, and then it is truly implemented in a code block, so as to complete the process of adding a pair of numbers to the seat.
- # Define find
- Def find (DIR)
- Dir. entries (DIR ). each {| f | yield f} # obtain the list of file names in the Dir directory. For each file name, yield is used for processing (as for how to handle it, I still don't know how to take the place first ^_^)
- End
- # Use Find
- Find (".") Do | f | # Start Block
- Puts F # Use the output file name statement to implement yield processing (you can also use any other statement)
- End # block end
# Define finddef find (DIR) dir. entries (DIR ). each {| f | yield f} # obtain the list of file names in the Dir directory. For each file name, yield is used for processing (as for how to handle it, I still don't know how to take the place first ^_^) end # Use findfind (". ") Do | f | # block start puts f # Use the output file name statement to implement yield processing (or use any other statement) end # block end
It can be seen that yield belongs to the definition layer and belongs to the declaration layer, that is, to say in my mind: "This is a good position. I will use books to take up the space first! "; And block belongs to the use layer, the Implementation Layer, that is, you finally sit in the position you previously occupied, so as to truly implement the process of seat check.
Finally, please do not ask me "what if the book is stolen? "Thank you for your cooperation.