1#
2#   irb/ext/cb.rb -
3#   	$Release Version: 0.9.6$
4#   	$Revision: 38515 $
5#   	by Keiju ISHITSUKA(keiju@ruby-lang.org)
6#
7# --
8#
9#
10#
11
12module IRB # :nodoc:
13  class Context
14
15    # Inherited from +TOPLEVEL_BINDING+.
16    def home_workspace
17      if defined? @home_workspace
18	@home_workspace
19      else
20	@home_workspace = @workspace
21      end
22    end
23
24    # Changes the current workspace to given object or binding.
25    #
26    # If the optional argument is omitted, the workspace will be
27    # #home_workspace which is inherited from +TOPLEVEL_BINDING+ or the main
28    # object, <code>IRB.conf[:MAIN_CONTEXT]</code> when irb was initialized.
29    #
30    # See IRB::WorkSpace.new for more information.
31    def change_workspace(*_main)
32      if _main.empty?
33	@workspace = home_workspace
34	return main
35      end
36
37      @workspace = WorkSpace.new(_main[0])
38
39      if !(class<<main;ancestors;end).include?(ExtendCommandBundle)
40	main.extend ExtendCommandBundle
41      end
42    end
43
44#     def change_binding(*_main)
45#       back = @workspace
46#       @workspace = WorkSpace.new(*_main)
47#       unless _main.empty?
48# 	begin
49# 	  main.extend ExtendCommandBundle
50# 	rescue
51# 	  print "can't change binding to: ", main.inspect, "\n"
52# 	  @workspace = back
53# 	  return nil
54# 	end
55#       end
56#       @irb_level += 1
57#       begin
58# 	catch(:SU_EXIT) do
59# 	  @irb.eval_input
60# 	end
61#       ensure
62# 	@irb_level -= 1
63#  	@workspace = back
64#       end
65#     end
66#     alias change_workspace change_binding
67  end
68end
69
70