Module: ButterflyNet::Commands
- Defined in:
- lib/butterfly_net/commands.rb
Instance Method Summary collapse
- #bn_close ⇒ Object (also: #bnc)
- #bn_open(file_name = nil) ⇒ Object (also: #bn)
Instance Method Details
#bn_close ⇒ Object Also known as: bnc
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/butterfly_net/commands.rb', line 24 def bn_close check_for_readline if @file status = @file.close @file = nil status else puts "butterfly_net: First invoke 'bn' or 'bn_open' to begin a session" false end end |
#bn_open(file_name = nil) ⇒ Object Also known as: bn
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/butterfly_net/commands.rb', line 12 def bn_open(file_name=nil) @file.close if @file check_for_readline start_index = Readline::HISTORY.empty? ? 0 : (Readline::HISTORY.size - 1) file_name ||= "butterfly_net_#{Time.now.strftime("%Y%m%d%H%M%S")}.rb" file_name += ".rb" unless file_name =~ /.rb$/ @file = FileWriter.new(file_name, start_index) Kernel.at_exit { puts @file.close if @file; @file = nil } puts "butterfly_net: #{file_name} opened at Readline::HISTORY ##{start_index}" true end |