1#
2#   push-ws.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    # Size of the current WorkSpace stack
16    def irb_level
17      workspace_stack.size
18    end
19
20    # WorkSpaces in the current stack
21    def workspaces
22      if defined? @workspaces
23	@workspaces
24      else
25	@workspaces = []
26      end
27    end
28
29    # Creates a new workspace with the given object or binding, and appends it
30    # onto the current #workspaces stack.
31    #
32    # See IRB::Context#change_workspace and IRB::WorkSpace.new for more
33    # information.
34    def push_workspace(*_main)
35      if _main.empty?
36	if workspaces.empty?
37	  print "No other workspace\n"
38	  return nil
39	end
40	ws = workspaces.pop
41	workspaces.push @workspace
42	@workspace = ws
43	return workspaces
44      end
45
46      workspaces.push @workspace
47      @workspace = WorkSpace.new(@workspace.binding, _main[0])
48      if !(class<<main;ancestors;end).include?(ExtendCommandBundle)
49	main.extend ExtendCommandBundle
50      end
51    end
52
53    # Removes the last element from the current #workspaces stack and returns
54    # it, or +nil+ if the current workspace stack is empty.
55    #
56    # Also, see #push_workspace.
57    def pop_workspace
58      if workspaces.empty?
59	print "workspace stack empty\n"
60	return
61      end
62      @workspace = workspaces.pop
63    end
64  end
65end
66
67