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 1008255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:44:37+00:00 2026-05-16T08:44:37+00:00

It looks like in ruby 1.9.2 if to_s is defined, inspect will return to_s??

  • 0

It looks like in ruby 1.9.2 if to_s is defined, inspect will return to_s?? Why would this change?

This:

class ToSClass
  def to_s
    "#{self.class.name} to_s called"
  end
end
class InspectClass
  def inspect
    "#{self.class.name} inspect called"
  end
end
class BothClass
  def inspect
    "#{self.class.name} inspect called"
  end
  def to_s
    "#{self.class.name} to_s called"
  end
end

c1 = ToSClass.new
puts c1.inspect
puts c1.to_s
c1 = InspectClass.new
puts c1.inspect
puts c1.to_s
c1 = BothClass.new
puts c1.inspect
puts c1.to_s

outputs this:

ToSClass to_s called
ToSClass to_s called
InspectClass inspect called
#<InspectClass:0x316baf8>
BothClass inspect called
BothClass to_s called
  • 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-16T08:44:38+00:00Added an answer on May 16, 2026 at 8:44 am

    Object#inspect will call to_s if available. I don’t think the behavior has changed.

    I’ve run your program on 1.9.2 and 1.8.7 and don’t see any difference.

    $ rvm inspect.rb 1.9.2,1.9.1,1.8.7
    
    info: 1.9.2 (ruby-1.9.2-p0): ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux] 
    
    ToSClass to_s called
    ToSClass to_s called
    InspectClass inspect called
    #<InspectClass:0x00000001941c80>
    BothClass inspect called
    BothClass to_s called
    
    info: 1.9.1 (ruby-1.9.1-p378): ruby 1.9.1p378 (2010-01-10 revision 26273) [x86_64-linux] 
    
    ToSClass to_s called
    ToSClass to_s called
    InspectClass inspect called
    #<InspectClass:0x000000011594b8>
    BothClass inspect called
    BothClass to_s called
    
    info: 1.8.7 (ruby-1.8.7-p302): ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux] 
    
    ToSClass to_s called
    ToSClass to_s called
    InspectClass inspect called
    #<InspectClass:0x7ffd795afd60>
    BothClass inspect called
    BothClass to_s called
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

my ruby (on rails) class looks like: class Foo def self.method1 someAction end def
We have a model association that looks something like this: class Example < ActiveRecord::Base
It looks like we'll be adding CAPTCHA support to Stack Overflow. This is necessary
Update: looks like this is indeed a WiX limitation - Cannot add 64bit com+
I have some trivial markup that looks like the following: <li class=someclass> <=% t'model.attr'
I feel like this will end in a facepalm moment but I've been banging
I was kidding with metaprogramming in Ruby and I did this code: class Class
Looks like here in StackOveflow there is a group of F# enthusiasts. I'd like
Looks like my only option is to create a mutatant child of the tree
Update : Looks like the query does not throw any timeout. The connection is

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.