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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:39:30+00:00 2026-05-13T08:39:30+00:00

I am using Ruby 1.8.6 for the following code: # Create an array and

  • 0

I am using Ruby 1.8.6 for the following code:

# Create an array and override the #to_s on that object
thing = [1,2,3]
def thing.to_s
  'one'
end

print "Using print: "
print thing

puts
puts "Using puts: "
puts thing

Output:

Using print: one
Using puts: 
1
2
3

So thing is an Array and I have overridden thing#to_s. print seems to use my overriden implementation while puts does not. Why?

I have followed the source code of Kernel#puts and Kernel#print (which are C-implementations) and see that they are very different implementations. I want to know what might be the design-decision (if any) behind this?

By the way, if I create thing as an instance of another class I wrote (or as a Hash/String/other-classes I tried), both print and puts use the overridden implementation of to_s.

  • 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-13T08:39:30+00:00Added an answer on May 13, 2026 at 8:39 am

    From the Ruby Programming Language:
    alt text http://ecx.images-amazon.com/images/I/41n-JSlBHkL._SL75_.jpg

    Output streams are appendable, like strings and arrays are, and you can write values to them with the << operator. puts is one of the most common output methods. It converts each of its arguments to a string, and writes each one to the stream. If the string does not already end with a newline character, it adds one. If any of the arguments to puts is an array, the array is recursively expanded, and each element is printed on its own line as if it were passed directly as an argument to puts. The print method converts its arguments to strings, and outputs them to the stream. If the global field separator $, has been changed from its default value of nil, then that value is output between each of the arguments to print. If the output record separator $/ has been changed from its default value of nil, then that value is output after all arguments are printed.

    As for design decisions, that I do not know.

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

Sidebar

Related Questions

Using Ruby 1.9.2, Rails 3.1. I have the following code: # review.rb def calculate_rating(reviewable)
I'm using the following view code in my Ruby (1.9.3) on Rails (3.1) application
I was wondering how can I generate the following array using ranges in ruby
I am using the following code to dynamically create an INPUT element and assign
Using ruby regexp I get the following results: >> 'foobar'[/o+/] => oo >> 'foobar'[/o*/]
I have gotten the following errors using ruby 1.9.2-p320 with Heroku's Taps-using 'db' commands
I am using Ruby on Rails 3.2.2 and Ruby 1.9.2. Given the following multidimensional
I am using the thrift ruby gem and am doing the following serializer =
I am using following command for start the production server. nohup ruby script/server webrick
I am using the following Spreadsheet gem to generate an excel sheet from ruby-on-rails..

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.