Ruby Build an Address Book in Ruby Class Design Write a to_s Method

Ruby: the format was incorrect. Can you help me?

Hello, I don't understand what's happening thought I tried to respect the syntax in the to_s method. Can you help me?

class PhoneNumber
  attr_reader :kind, :number

  def initialize(kind, number)
    @kind = kind
    @number = number

 def to_s 
   puts "#{kind}: #{number}"


1 Answer

Claire Beauvais Lightner
Claire Beauvais Lightner
853 Points

Hello Mouhamadou,

First of all great job on your method and learning!

Regarding your question, The problem is coming from "puts" since puts (short for put strings) adds a newline after executing. Removing "puts" will solve the format problem.

No need to add "return <code>" as well since any statement in Ruby returns the value of the last evaluated expression. (implicit return).


Thanks a lot!