From: Paul Roche Date: 2010-11-14T02:33:05+09:00 Subject: Re: an each/block problem Hassan Schroeder wrote in post #961211: > On Sat, Nov 13, 2010 at 8:08 AM, Paul Roche > wrote: >> Just one more thing. if I want to attach the 'name' of the User to that. >> How can I do it? >> >> i.e so the print out is "User1: you can borrow more" > > Pass the entire User object, e.g. `borrowed.call(user)` and change > your proc to: > > borrowed = lambda do |user| > if user.books_borrowed > 1 then p "#{user.name}: you have borrowed too > many" > else puts "#{user.name}: you can borrow more" > end > end > > or have it take 2 arguments, user.name and user.books_borrowed, > exercise left to the reader :-) > > HTH, Thanks for that. I am arranging to take 2 parameters... users = User.find(:all) users.each {|namex, user| nameb.call(namex.name) borrowed.call(user.books_borrowed) } I get the following error.... books.rb:80: syntax error, unexpected ',', expecting '}'users.each {|namex,user| (nameb.call(namex.name)), (borrowed.call(user.books_borrowed)) } ps Thanks Phillip Gawlowski for that detail :) -- Posted via http://www.ruby-forum.com/.