Last active
August 29, 2015 14:09
-
-
Save jasonblanchard/e4e992392b2b67ec1ae1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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