What is the difference between those syntax?
Is there any benefit with the first over the second?
agent = Mechanize.new
# first
agent.get(url) do |page|
work
end
#second
page = agent.get(url)
Which one should I use when and why?
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.
The two ways of calling the get method end up doing the same thing. You can use it either way you like. The first way where it allows you to pass a block might be useful in writing more concise and/or readable code. Its up to you to choose whichever fits your need. Take for example;
which reads better than
Same case applies when doing Mechanize initialization. I prefer
to
}