Class: JSH::REPL
- Inherits:
-
Object
- Object
- JSH::REPL
- Defined in:
- lib/jsh/repl.rb
Constant Summary collapse
- DEFAULT_PROMPT =
"[{:number_of_times:}] jsh) "- PROMPT_SYNTAX =
/\{:(.+?):\}/
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#prompt ⇒ Object
Returns the value of attribute prompt.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(base, options = {}) ⇒ REPL
constructor
A new instance of REPL.
- #noprompt? ⇒ Boolean
- #readline? ⇒ Boolean
- #repl ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(base, options = {}) ⇒ REPL
15 16 17 18 19 20 21 |
# File 'lib/jsh/repl.rb', line 15 def initialize(base, = {}) @base = base @noprompt = .fetch(:noprompt, false) @readline = .fetch(:readline, true) = config[:number_of_times] = 0 end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
9 10 11 |
# File 'lib/jsh/repl.rb', line 9 def base @base end |
#prompt ⇒ Object
Returns the value of attribute prompt.
9 10 11 |
# File 'lib/jsh/repl.rb', line 9 def prompt @prompt end |
Class Method Details
.start(options) ⇒ Object
11 12 13 |
# File 'lib/jsh/repl.rb', line 11 def self.start() new(Base.new, ).start end |
Instance Method Details
#noprompt? ⇒ Boolean
43 44 45 |
# File 'lib/jsh/repl.rb', line 43 def noprompt? @noprompt end |
#readline? ⇒ Boolean
47 48 49 |
# File 'lib/jsh/repl.rb', line 47 def readline? @readline end |
#repl ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/jsh/repl.rb', line 29 def repl catch :halt do loop do input = read if command = commands[input.to_sym] command.arity != 0 ? command.call(base) : command.call else output.puts((input.nil? or input.empty?) ? "" : base.context.eval(input)) end config[:number_of_times] += 1 end end end |
#start ⇒ Object
23 24 25 26 27 |
# File 'lib/jsh/repl.rb', line 23 def start call_hook(:before) repl call_hook(:after) end |