Module: SR
- Defined in:
- lib/sr.rb,
lib/sr/version.rb
Overview
‘sr` is a simple, tiny, hackable REPL for Ruby.
Constant Summary collapse
- CONFIGURATION_FILES =
The array of known configuration files for SR which should be loaded when the read-eval-print loop is started.
(XDG_CONFIG_DIRS + [XDG_CONFIG_HOME]).map! do |dir| (File.(dir) + '/sr/config.rb').freeze end.select! { |file| File.exist?(file) }.freeze
- CONTINUATION_REGEXP =
The regular expression used to determine whether or not a syntax error is a valid continuation which should prompt for more user input.
/unterminated (?:regexp|string)|unexpected end-of-input|tIDENTIFIER/- VERSION =
Semantic version of ‘sr`.
'1.0.0'
Class Attribute Summary collapse
-
.context ⇒ Binding
readonly
The currently bound SR context.
-
.handlers ⇒ Hash{Class=>#call}
readonly
The hash of exception handlers.
-
.prompt ⇒ Hash{Symbol=>#call,#to_s}
readonly
The hash of prompts to display; valid keys are ‘:error`, `:input`, `:more`, and `:return`; valid values must respond to `#to_s`.
Class Method Summary collapse
-
.bind(object) ⇒ Binding
(also: context=)
The new SR context.
-
.repl(context = nil) ⇒ void
Loads the configuration for SR, resets the default binding to the given ‘context`, and starts the read-eval-print loop.
-
.reset_binding(context = nil) ⇒ Binding
The reset binding context.
-
.stack ⇒ Array<Binding>
A copy of the SR context stack.
-
.unbind ⇒ Binding
The previous binding in the SR context stack or the default context if no previous binding exists.
Class Attribute Details
.context ⇒ Binding (readonly)
Returns the currently bound SR context.
10 11 12 |
# File 'lib/sr.rb', line 10 def context @context end |
.handlers ⇒ Hash{Class=>#call} (readonly)
Returns the hash of exception handlers.
13 14 15 |
# File 'lib/sr.rb', line 13 def handlers @handlers end |
.prompt ⇒ Hash{Symbol=>#call,#to_s} (readonly)
Returns the hash of prompts to display; valid keys are ‘:error`, `:input`, `:more`, and `:return`; valid values must respond to `#to_s`.
18 19 20 |
# File 'lib/sr.rb', line 18 def prompt @prompt end |
Class Method Details
.bind(object) ⇒ Binding Also known as: context=
Returns the new SR context.
61 62 63 64 |
# File 'lib/sr.rb', line 61 def self.bind(object) @stack.push(@context) @context = object.__binding__ end |
.repl(context = nil) ⇒ void
This method returns an undefined value.
Loads the configuration for SR, resets the default binding to the given ‘context`, and starts the read-eval-print loop.
122 123 124 125 126 127 |
# File 'lib/sr.rb', line 122 def self.repl(context = nil) load_configuration reset_binding(context) unless context.nil? @enabled = true read_eval_print while @enabled end |
.reset_binding(context = nil) ⇒ Binding
Returns the reset binding context.
76 77 78 79 80 |
# File 'lib/sr.rb', line 76 def self.reset_binding(context = nil) @stack.clear context = context.__binding__ unless context.nil? @context = @ORIGINAL_CONTEXT = context ? context : TOPLEVEL_BINDING end |
.stack ⇒ Array<Binding>
Returns a copy of the SR context stack.
55 56 57 |
# File 'lib/sr.rb', line 55 def self.stack @stack.dup end |
.unbind ⇒ Binding
Returns the previous binding in the SR context stack or the default context if no previous binding exists.
69 70 71 |
# File 'lib/sr.rb', line 69 def self.unbind @context = @stack.empty? ? @ORIGINAL_CONTEXT : @stack.pop end |