Class: IRB::Kit::Handlers::Editor
- Defined in:
- lib/irb/kit/handlers/editor.rb
Overview
Handles editing of source code.
Instance Method Summary collapse
- #call(path, line = nil) ⇒ Object
-
#initialize(environment: ENV, kernel: Kernel) ⇒ Editor
constructor
A new instance of Editor.
Constructor Details
#initialize(environment: ENV, kernel: Kernel) ⇒ Editor
Returns a new instance of Editor.
8 9 10 11 12 |
# File 'lib/irb/kit/handlers/editor.rb', line 8 def initialize(environment: ENV, kernel: Kernel, **) @environment = environment @kernel = kernel super(**) end |
Instance Method Details
#call(path, line = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/irb/kit/handlers/editor.rb', line 14 def call path, line = nil path_and_line = [path, line].join ":" if path && Pathname(path).exist? io.puts "Editing: #{path_and_line}..." kernel.system %(#{environment.fetch "EDITOR"} #{path_and_line}) else io.puts "ERROR (invalid path): #{path}." end rescue KeyError then io.puts "ERROR: The `EDITOR` environment variable must be defined." end |