Reputation: 973
Once I do a rails c and get some rows form the db like so:
users = User.find(:all,:conditions => ["some conds"])
then users has say 20 results
If I then do a
users.each do |u|
puts u.name if u.gender == 'male'
end
then after printing all the male names, the console again outputs all the content of the users object. I don't need to see it again. How can I suppress it? All I am interested in is the output of puts
Upvotes: 3
Views: 2129
Reputation: 230286
That's how console works. You enter expression, it prints its value.
users.each do |u|
puts u.name if u.gender == 'male'
end
Value of this code is users
object itself and it is correctly printed. What you print with puts
is a side effect.
You can still suppress printing full contents of users
by changing return value of this expression. For example, like this:
users.each do |u|
puts u.name if u.gender == 'male'
end && false
Upvotes: 20