module TakeAMemo
Constants
- IRB_MEMO_DIR
Public Instance Methods
play_it_back(memo)
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
Private Instance Methods
create_file(title)
click to toggle source
# File lib/take_a_memo.rb, line 47 def create_file(title) FileUtils.mkdir_p(IRB_MEMO_DIR) unless File.exists?(IRB_MEMO_DIR) File.new("#{IRB_MEMO_DIR}/#{title.gsub(" ", "_")}.rb", "w") end
execute_commands(file)
click to toggle source
# File lib/take_a_memo.rb, line 52 def execute_commands(file) cmd = IO.read(file.path) output = eval cmd puts "memo returned: #{output.call}" end