How to suppress some output in the Rails console

Once I make rails c and get some lines from db like this:

users = User.find(:all,:conditions => ["some conds"])

      

then users will say 20 results

If I then do

users.each do |u|
  puts u.name if u.gender == 'male'
end

      

then after all male names have been printed, the console will again display the entire contents of the user object. I don't need to see this anymore. How can I suppress it? All I am interested in is the output of puts

+3


source to share


1 answer


How the console works. You enter an expression, it prints its value.

users.each do |u|
  puts u.name if u.gender == 'male'
end

      

The meaning of this code is the object itself users

and is printed correctly. What you are typing with puts

is a side effect.



You can still disable printing of the full content users

by changing the return value of this expression. For example, for example:

users.each do |u|
  puts u.name if u.gender == 'male'
end && false

      

+19


source







All Articles