Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

228
Views
Does Atom break ruby to_s override?

I want puts to return @value. The code is below:

class Tile
  def initialize(value, given=false)
    @value = value
    @given = given
  end

  def newValue(value)
    @value = value if @given == false
  end

  def to_s
    @value
  end

end

t = Tile.new(5)
t.newValue(6)
debugger
puts t

This results in the printing of just the object id, no variables.

Why? And what is going wrong here? Is it an Atom thing?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

puts prints each argument by calling its to_s method. It also expects the to_s method to return a string. If to_s returns something else it ignores that value and prints the object's class and id instead.

In your example, @value is an integer. To fix your code:

def to_s
  @value.to_s
end
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!