Class: RubyJournal
- Inherits:
-
Object
- Object
- RubyJournal
- Defined in:
- lib/ruby_journal.rb
Instance Method Summary collapse
-
#initialize ⇒ RubyJournal
constructor
A new instance of RubyJournal.
- #read_entries ⇒ Object
- #write_entry ⇒ Object
Constructor Details
#initialize ⇒ RubyJournal
Returns a new instance of RubyJournal.
2 3 4 |
# File 'lib/ruby_journal.rb', line 2 def initialize @entries = [] end |
Instance Method Details
#read_entries ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ruby_journal.rb', line 20 def read_entries if @entries.empty? puts "Your diary is empty. \u{1F4D6}" else puts "Diary Entries:" @entries.each_with_index do |entry, index| puts "#{index + 1}. #{entry[:timestamp]}:\n#{entry[:content]}\n\n" end end end |
#write_entry ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ruby_journal.rb', line 6 def write_entry puts "Write your diary entry (type exit to finish):" entry = "" loop do line = gets.chomp break if line.downcase == 'exit' entry += line +'\n' end @entries << {timestamp: Time.now, content: entry.chomp} puts "Entry saved successfully! \u{1F4D4}" end |