I have seen here and there code like this one
Specification.new do |s|
s.name = %q{casein}
s.version = "3.1.11"
....
Can someone explain me what is the idea behind “do |s|” ?
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.
This is an example of using blocks in ruby. Block is a chunk of code that you can pass to a method (
newis just a regular method).Here initializer in
Foocalles a block (if one is given) and passes it a parameters. Block then can receive that parameter and do its work.Educational reading here.