Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Im having a problem making a preview method with Ruby. instead of just preview the content it shows all of the content

class Note

attr_accessor :content, :notes @content @notes

def initialize(content) @content = content @notes = [] end

def add_note(content) notes.push(content) end

def print_notes(kind = 'full lists')

puts "#{content}" 
puts "-" * 30 
 puts @notes  

end

def preview if notes.length < 25 puts "Preview of notes:" puts "-" * 30 notes.each do |notes| if puts notes.slice(0..29) + ' (...)' end end
end end end

note = Note.new("my notes") note.add_note("I have to take my son to his appointment for a check up") note.add_note("I have to go to the bank to take out a loan") note.add_note("I have to go get my car inspected")

puts note.preview

this is what comes out

Preview of notes:

I have to take my son to his a (...)
I have to go to the bank to ta (...)
I have to go get my car inspec (...)
I have to take my son to his appointment for a check up
I have to go to the bank to take out a loan
I have to go get my car inspected

1 Answer

class Note

  attr_accessor :content, :notes
  @content
  @notes

  def initialize(content)
    @content = content
    @notes = []
  end

  def add_note(content)
    notes.push(content) 
  end

  def print_notes(kind = 'full lists')

    puts "#{content}" 
    puts "-" * 30 
     puts @notes  
  end  

  def preview
     if notes.length < 25
      puts "Preview of notes:"
      puts "-" * 30
      notes.each do |notes|
      if
      puts notes.slice(0..29) + ' (...)'
      end
      end    
      end
  end
end



note = Note.new("my notes")
note.add_note("I have to take my son to his appointment for a check up")
note.add_note("I have to go to the bank to take out a loan")
note.add_note("I have to go get my car inspected")

puts note.preview