lib/irb_hacks/snippet.rb in irb_hacks-0.1.1 vs lib/irb_hacks/snippet.rb in irb_hacks-0.2.0

- old
+ new

@@ -1,11 +1,12 @@ require "readline" module IrbHacks #:nodoc: module Snippet + #TODO: Configured values. Config is common for entire IrbHacks. HISTORY_FILE = File.join(ENV["HOME"], ".irb_snippet_history") - HISTORY_SIZE = 20 + HISTORY_SIZE = 500 # Edit code snippet. def self.edit ##p "R::H before", Readline::HISTORY.to_a ##p "@history at inv", @history @@ -53,16 +54,22 @@ YAML.load(content) rescue nil end - @history = [%{puts "YOUR test code here"}] if not @history.is_a? Array + @history = [%{puts "YOUR test code here"}] if not @history end # Run code snippet. + # If <tt>IrbHacks.break</tt> is called anywhere, immediately return its argument. def self.run(*args, &block) if (code = @history.last) - eval(code, &block) + begin + eval(code, &block) + rescue IrbHacks::BreakException => e + # If invoked as documented, `e.message` is always an array. + e.message[0] + end end end def self.save_history # Truncate a saved version of @history.