class IRuby::PlainBackend
Attributes
Public Class Methods
Source
# File lib/iruby/backend.rb, line 43 def initialize require 'irb' require 'irb/completion' IRB.setup(nil) @main = TOPLEVEL_BINDING.eval("self").dup init_main_object(@main) @workspace = IRB::WorkSpace.new(@main) @irb = IRB::Irb.new(@workspace) @eval_path = @irb.context.irb_path IRB.conf[:MAIN_CONTEXT] = @irb.context @completor = IRB::RegexpCompletor.new if defined? IRB::RegexpCompletor # IRB::VERSION >= 1.8.2 end
Public Instance Methods
Source
# File lib/iruby/backend.rb, line 71 def complete(code) if @completor # preposing and postposing never used, so they are empty, pass only target as code @completor.completion_candidates('', code, '', bind: @workspace.binding) else IRB::InputCompletor::CompletionProc.call(code) end end
Source
# File lib/iruby/backend.rb, line 60 def eval(code, store_history) @irb.context.evaluate(parse_code(code), 0) @irb.context.last_value unless IRuby.silent_assignment && assignment_expression?(code) end
Source
# File lib/iruby/backend.rb, line 65 def parse_code(code) return code if Gem::Version.new(IRB::VERSION) < Gem::Version.new('1.13.0') return @irb.parse_input(code) if @irb.respond_to?(:parse_input) return @irb.build_statement(code) if @irb.respond_to?(:build_statement) end
Private Instance Methods
Source
# File lib/iruby/backend.rb, line 90 def assignment_expression?(code) @irb.respond_to?(:assignment_expression?) && @irb.assignment_expression?(code) end
Source
# File lib/iruby/backend.rb, line 82 def init_main_object(main) wrapper_module = Module.new main.extend(wrapper_module) main.define_singleton_method(:include) do |*args| wrapper_module.include(*args) end end