Skip to content

Instantly share code, notes, and snippets.

@jasonblanchard
Last active August 29, 2015 14:09
Show Gist options
  • Select an option

  • Save jasonblanchard/e4e992392b2b67ec1ae1 to your computer and use it in GitHub Desktop.

Select an option

Save jasonblanchard/e4e992392b2b67ec1ae1 to your computer and use it in GitHub Desktop.
class Note
attr_accessor :content
def initialize(content)
@content = content
end
def preview
if @content.length < 30
@content
else
@content.slice(0..29) + ' (...)'
end
end
end
require './note'
note1 = Note.new("Things I learned from RailsGuides: Rails emphasizes DRY as a core principle and that it embodies Convention Over Configuration as a core aspect of the framework")
note2 = Note.new("The answer is 42")
note3 = Note.new("Interesting gotcha from Stack Overflow ruby-on-rails tag - calling 'save'' with the exclamation mark (like, 'save!') raises an exception if the save failed validation, but calling it without the exclamation point fails silently")
notes = [note1, note2, note3]
puts "Preview of my notes:"
notes.each do |note|
puts note.preview
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment