Module: TakeAMemo
- Defined in:
- lib/take_a_memo.rb
Constant Summary collapse
- IRB_MEMO_DIR =
ENV['IRB_MEMO_DIR'] || "#{ENV['HOME']}/.irb_memos"
Instance Method Summary collapse
- #play_it_back(memo) ⇒ Object
- #show_my_memos ⇒ Object
- #take_a_memo(title, &block) ⇒ Object
- #trash_this_memo(memo) ⇒ Object
Instance Method Details
#play_it_back(memo) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/take_a_memo.rb', line 19 def play_it_back(memo) unless file = File.open("#{IRB_MEMO_DIR}/#{memo.gsub(" ", "_")}.rb") puts "couldn't find file for #{memo}" return end execute_commands(file) end |
#show_my_memos ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/take_a_memo.rb', line 28 def show_my_memos unless File.exists?(IRB_MEMO_DIR) and Dir.entries(IRB_MEMO_DIR).size > 0 puts "you have no saved memos" return end puts %Q|Here's your memos:\n| puts Dir.entries(IRB_MEMO_DIR).reject {|m| m =~ /^\./ }.map {|m| "\t - #{m.gsub(".rb", "").gsub("_", " ")}" }.join("\n") end |
#take_a_memo(title, &block) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/take_a_memo.rb', line 8 def take_a_memo(title, &block) unless block_given? puts "nothing to remember here!" return end file = create_file(title) file.write(block.to_raw_source) file.close execute_commands(file) end |
#trash_this_memo(memo) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/take_a_memo.rb', line 37 def trash_this_memo(memo) unless File.exists?("#{IRB_MEMO_DIR}/#{memo.gsub(" ", "_")}.rb") puts "couldn't find file to remove for #{memo}" end FileUtils.rm("#{IRB_MEMO_DIR}/#{memo.gsub(" ", "_")}.rb") end |