<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/the-difference-between-to-s-to-str-in-ruby-x5olpzmtz" -->

---
title: The Difference Between to_s &amp; to_str In Ruby | daily.dev
description: Ruby provides two string conversion methods, `to_s` and `to_str`, that serve fundamentally different purposes. `to_s` is defined on virtually all objects and...
canonical: https://daily.dev/posts/the-difference-between-to-s-to-str-in-ruby-x5olpzmtz
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: The Difference Between to_s &amp; to_str In Ruby | daily.dev
og:description: Ruby provides two string conversion methods, `to_s` and `to_str`, that serve fundamentally different purposes. `to_s` is defined on virtually all objects and...
og:url: https://daily.dev/posts/the-difference-between-to-s-to-str-in-ruby-x5olpzmtz
og:image: https://api.daily.dev/og/posts/x5OlPzMTz.png
og:image:alt: The Difference Between to_s &amp; to_str In Ruby
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# The Difference Between to_s & to_str In Ruby

**[Marc G Gauthier](https://daily.dev/sources/marcgg)** · 5 min read · 0 upvotes · 0 comments

## Summary

Ruby provides two string conversion methods, `to_s` and `to_str`, that serve fundamentally different purposes. `to_s` is defined on virtually all objects and returns a string representation for display purposes — it's an explicit conversion. `to_str`, by contrast, is an implicit conversion that signals the object behaves like a string and can be used wherever a String is expected. Only the `String` class in Ruby core implements `to_str`. Defining `to_str` on a custom class enables implicit coercion, for example allowing concatenation with `+` without explicit casting. The same distinction applies to analogous method pairs like `to_int`/`to_i`, `to_ary`/`to_a`, and others.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://marcgg.com/blog/2017/01/23/ruby-to-s-to-str/>

## Similar posts on daily.dev

- [Understanding How Symbols Differ From Strings](https://daily.dev/posts/understanding-how-symbols-differ-from-strings-tqzp088yt) · RUBYLAND · 0 upvotes · 0 comments
- [How to Use Rails Magic Methods in Plain Ruby Scripts](https://daily.dev/posts/how-to-use-rails-magic-methods-in-plain-ruby-scripts-snabw6esq) · Ruby Flow · 1 upvotes · 0 comments
- [Some Smalltalk about Ruby Loops](https://daily.dev/posts/some-smalltalk-about-ruby-loops-gv2dmqisd) · Lobsters · 0 upvotes · 0 comments
- [Ruby Floats: When 2.6x Faster Is Actually Slower](https://daily.dev/posts/ruby-floats-when-2-6x-faster-is-actually-slower-e5wbxhxja) · RUBYLAND · 0 upvotes · 0 comments

---

Tags: [#ruby](https://daily.dev/tags/ruby), [#rails](https://daily.dev/tags/rails)

[View this post on daily.dev](https://daily.dev/posts/the-difference-between-to-s-to-str-in-ruby-x5olpzmtz)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"The Difference Between to_s & to_str In Ruby","url":"https://daily.dev/posts/the-difference-between-to-s-to-str-in-ruby-x5olpzmtz","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/the-difference-between-to-s-to-str-in-ruby-x5olpzmtz"},"datePublished":"2026-03-26T08:36:04.939Z","dateModified":"2026-03-26T08:38:08.730Z","description":"Ruby provides two string conversion methods, `to_s` and `to_str`, that serve fundamentally different purposes. `to_s` is defined on virtually all objects and...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/6087b506fd9f46cd2a50786c4e382655?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/6087b506fd9f46cd2a50786c4e382655?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Marc G Gauthier","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Marc G Gauthier","logo":"https://media.daily.dev/image/upload/s--P4lsZKFE--/f_auto,q_auto/v1774514113/logos/marcgg?_a=BAMAMiWQ0","url":"https://daily.dev/sources/marcgg"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/the-difference-between-to-s-to-str-in-ruby-x5olpzmtz","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"ruby,rails","timeRequired":"PT5M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Marc G Gauthier","item":"https://daily.dev/sources/marcgg"},{"@type":"ListItem","position":3,"name":"The Difference Between to_s & to_str In Ruby"}]}
```

