Class: Heyruby::Console
- Inherits:
-
Object
- Object
- Heyruby::Console
- Defined in:
- lib/heyruby/console.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Console
constructor
A new instance of Console.
- #normal_prompt(obj, nest_level, pry) ⇒ Object
- #prompt_for_hypothesis(line, pry) ⇒ Object
- #start ⇒ Object
- #wait_prompt(obj, nest_level, pry) ⇒ Object
Constructor Details
#initialize ⇒ Console
Returns a new instance of Console.
6 7 8 9 10 11 12 13 |
# File 'lib/heyruby/console.rb', line 6 def initialize Pry.config.should_load_rc = false Pry.config.prompt = [method(:normal_prompt), method(:wait_prompt)] Pry.hooks.add_hook :after_read, :prompt_for_hypothesis do |line, pry| prompt_for_hypothesis line, pry end @pry = Pry end |
Class Method Details
.start ⇒ Object
46 47 48 |
# File 'lib/heyruby/console.rb', line 46 def self.start new.start end |
Instance Method Details
#normal_prompt(obj, nest_level, pry) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/heyruby/console.rb', line 15 def normal_prompt obj, nest_level, pry if @hypothesis @hypothesis = nil "Were you right?\nTry somthing else> " else "Hey Ruby‽> " end end |
#prompt_for_hypothesis(line, pry) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/heyruby/console.rb', line 28 def prompt_for_hypothesis line, pry print %Q<What do you think the result of ``` #{CodeRay.scan(line, :ruby).term} ``` will be? (Type . on a line by itself when done) | > @hypothesis = [] while (str = readline.chomp!) != "." print "| " @hypothesis << str end end |
#start ⇒ Object
42 43 44 |
# File 'lib/heyruby/console.rb', line 42 def start @pry.start end |
#wait_prompt(obj, nest_level, pry) ⇒ Object
24 25 26 |
# File 'lib/heyruby/console.rb', line 24 def wait_prompt obj, nest_level, pry "Hey Ruby‽* " end |