# frozen_string_literal: true # # irb/workspace-binding.rb - # by Keiju ISHITSUKA(keiju@ruby-lang.org) # require "delegate" require_relative "helper_method" IRB::TOPLEVEL_BINDING = binding module IRB # :nodoc: class WorkSpace # Creates a new workspace. # # set self to main if specified, otherwise # inherit main from TOPLEVEL_BINDING. def initialize(*main) if main[0].kind_of?(Binding) @binding = main.shift elsif IRB.conf[:SINGLE_IRB] @binding = TOPLEVEL_BINDING else case IRB.conf[:CONTEXT_MODE] when 0 # binding in proc on TOPLEVEL_BINDING @binding = eval("proc{binding}.call", TOPLEVEL_BINDING, __FILE__, __LINE__) when 1 # binding in loaded file require "tempfile" f = Tempfile.open("irb-binding") f.print <IRB.conf[:__MAIN__] attr_reader :main def load_helper_methods_to_main ancestors = class<' : '', current_pos + 1, lines[current_pos]) end.join("") "\nFrom: #{file} @ line #{pos + 1} :\n\n#{body}#{Color.clear}\n" end end module HelpersContainer def self.install_helper_methods HelperMethod.helper_methods.each do |name, helper_method_class| define_method name do |*args, **opts, &block| helper_method_class.instance.execute(*args, **opts, &block) end unless method_defined?(name) end end install_helper_methods end end