Working with Rails console can get really messy when you're dealing with large datasets or complex objects. Every time you run a query, the console spits out tons of output that you don't always need to see.
Here's a simple trick I learned to keep things clean:
Problem:
User.all
# => [#<User id: 1, name: "John", email: "john@example.com", created_at: "2011-01-13 10:30:00", updated_at: "2011-01-13 10:30:00">, #<User id: 2, name: "Jane", email: "jane@example.com", created_at: "2011-01-13 10:31:00", updated_at: "2011-01-13 10:31:00">, ...]
Solution 1: Use semicolon
User.all;
# => 1000 (just shows count)
Solution 2: Assign to underscore variable
_ = User.all
# => (no output)
Solution 3: Use null output
User.all > /dev/null
# => (no output)
Solution 4: Configure IRB/console globally
# Add to ~/.irbrc
IRB.conf[:ECHO] = false # Suppress all output
Solution 5: Use puts with return nil
puts User.all.size; nil
# => 1000
# => nil
Solution 6: Redirect to variable and show count
users = User.all
puts "Found #{users.size} users"
# => Found 1000 users
Solution 7: Use tap for side effects
User.all.tap { |users| puts "#{users.size} users loaded" }
# => 1000 users loaded
The semicolon trick is my favorite because it's quick and still gives you feedback about what happened. Very handy when you're debugging and don't want to scroll through pages of object dumps.