Came across this code.
def setup(&block)
@setups << block
end
What does this line do?
@setups << block
Interested in what the does “<<“.
The manual says that it is the operator of double shift, but he is here with?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For an array
<<is the append method. It adds an item to the end of the array.So in your specific case when you call
setupwith a block theProcobject made from the block is stored in@setups.Note: as sbeam points out in his comment, because
<<is a method, it can do different things depending on the type of object it is called on e.g. concatenation on strings, bit shifting on integers etc.See the “ary << obj → ary” documentation.