Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6997521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:17:39+00:00 2026-05-27T20:17:39+00:00

When viewing an Active Record object in Rails (ex. Foo.find(1) ) in the console,

  • 0

When viewing an Active Record object in Rails (ex. Foo.find(1) ) in the console, you get back something like:

=> #<Foo id: 1, name: "Far">

which shows the model name and each active record field from the database, without showing the same @instance variables, which in this case would be @far=.

How can I get the same representation for regular class objects, which instead return, with name defined as an attr_accessor:

=> #<Foo:0x00000102fbf970 @name="Far">

The reason why I want this is to be able to see the values for a set of methods on a class, instead of only seeing the attr_accessor (or attr_reader) method variables.

Is there a method that defines what the output of an object is?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:17:39+00:00Added an answer on May 27, 2026 at 8:17 pm

    The output in irb is done by calling Object#inspect which in turn calls Object#to_s. You can override either one of these. I tend to think of inspect as the debug view, and to_s as the standard user display.

    class Foo
      attr_accessor :bar, :value
    
      def to_s
        @value
      end
    
      def inspect
        "bar: #{@bar}, value: #{@value}"
      end
    end
    

    YMMV

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When viewing piped output to Less, sometimes I'd like to be able to view
I get errors when viewing forms and there are not any. I can close
What's the best tool for viewing and editing a merge in Git? I'd like
I'm new to Rails and i'm currently learning from tutorials from http://ruby.railstutorial.org/chapters/modeling-and-viewing-users-one#top find_by_email works
Viewing source, I have table data formatted exactly like this: <tr class=even> <td>apple</td> <td>pear</td>
From viewing the source code that this code makes it looks like itemValue generate
My UITableViewCells take up the full viewing area. I'd like to use a grouped
I'm using a JViewport for viewing some data and I'd like the header row
I am following Michael Hartl's Rails Tutorial Here: http://ruby.railstutorial.org/chapters/modeling-and-viewing-users-one#top I use this command to
Are there any references to the Active Directory attributes that Outlook uses when viewing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.