From: Paul Roche Date: 2010-11-14T01:05:49+09:00 Subject: Re: an each/block problem Hassan Schroeder wrote in post #961207: > On Sat, Nov 13, 2010 at 7:46 AM, Paul Roche > wrote: > >> I have a table called User which has a books_borrowed column. I'd like >> to stick to this lambda if at all possible :) >> >> >> borrowed = lambda do |x| >> if x > 1 then p "you have borrowed too many" >> else puts "you can borrow more" >> end >> end > > Wouldn't that just be: > > users = User.all > users.each {|user| borrowed.call(user.books_borrowed) } > > ? Indeed you're right. I didn't think of trying it, because I thought that borrowed.call wouldn't be accessable in the block. Thanks for that. Infact this is the complete working code....... users = User.find(:all) users.each {|user| borrowed.call(user.books_borrowed) } -- Posted via http://www.ruby-forum.com/.