# \[Bug:1.9\] RubyGems $B$N(B CommandManager $B$,(B singleton $B$K$J$C$F$$$J$$(B

**URL:** <https://www.ruby-forum.com/t/bug-1-9-rubygems-b-n-b-commandmanager-b-b-singleton-b-k-j-c-f-j-b/146871>\
**Category:** Development\
**Created:** [August 26, 2008, 10:31am UTC](https://www.ruby-forum.com/t/bug-1-9-rubygems-b-n-b-commandmanager-b-b-singleton-b-k-j-c-f-j-b/146871 "2008-08-26T10:31:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![okkez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/8edcca/32.png) [@okkez](https://www.ruby-forum.com/u/okkez)\
**Post date:** [August 26, 2008, 10:31am UTC](https://www.ruby-forum.com/t/bug-1-9-rubygems-b-n-b-commandmanager-b-b-singleton-b-k-j-c-f-j-b/146871/1 "2008-08-26T10:31:10Z")

</div>

okkez e$B$G$9!#e(B

lib/rubygems/command\_manager.rb e$B$GDj5A$5$l$F$$$ke(B  
Gem::CommandManager e$B%/%i%9$G$9$,!"%=!\<%9%3!\<%I$rFI$s$G$\_$?8B$j$G$Oe(B  
singleton e$B$K$7$?$+$C$?$N$8$c$J$$$+$H;W$&$N$G$9$,$$$+$,$G$7$g$&$+!)e(B

e$B85$N%3!\<%I$@$He(B Gem::CommandManager.instance  
e$B$GKh2s?7$7$$%$%s%9%?%s%9e(B  
e$B$,@8@.$5$l$^$9!#e(B  
e$B=$@5$K$"$o$;$F%F%9%H$b=$@5$7$F$\_$^$7$?!#e(B

e$B$h$m$7$/$\*4j$$$7$^$9!#e(B

# Index: lib/rubygems/command\_manager.rb

— lib/rubygems/command\_manager.rb (revision 18866)  
+++ lib/rubygems/command\_manager.rb (working copy)  
@@ -4,6 +4,7 @@

# See LICENSE.txt for permissions.

#++

+require ‘singleton’  
require ‘timeout’  
require ‘rubygems/command’  
require ‘rubygems/user\_interaction’  
@@ -15,12 +16,8 @@

# sub-commands supported by the gem command.

class CommandManager  
include UserInteraction

- include Singleton

- 
# Return the authoritative instance of the command manager.
- def self.instance

- 

```
 @command_manager ||= CommandManager.new

```

- end

- 
# Register all the subcommands supported by the gem command.

def initialize  
@commands = {}  
Index: test/rubygems/test\_gem\_command\_manager.rb  
===================================================================  
— test/rubygems/test\_gem\_command\_manager.rb (revision 18866)  
+++ test/rubygems/test\_gem\_command\_manager.rb (working copy)  
@@ -25,7 +25,7 @@  
def setup  
super

- @command\_manager = Gem::CommandManager.new

- @command\_manager = Gem::CommandManager.instance  
end

# def test\_run\_interrupt Index: test/rubygems/functional.rb

— test/rubygems/functional.rb (revision 18866)  
+++ test/rubygems/functional.rb (working copy)  
@@ -47,7 +47,7 @@  
end

def test\_all\_command\_helps

- mgr = Gem::CommandManager.new

- mgr = Gem::CommandManager.instance  
mgr.command\_names.each do |cmdname|  
gem\_nossl “help #{cmdname}”  
assert\_match(/Usage: gem #{cmdname}/, @out,

---

<div class="post-metadata">

**Author:** ![okkez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/8edcca/32.png) [@okkez](https://www.ruby-forum.com/u/okkez)\
**Post date:** [September 3, 2008, 4:35am UTC](https://www.ruby-forum.com/t/bug-1-9-rubygems-b-n-b-commandmanager-b-b-singleton-b-k-j-c-f-j-b/146871/2 "2008-09-03T04:35:57Z")

</div>

e$B%A%1%C%He(B #499 e$B$,99?7$5$l$^$7$?!#e(B (by okkez \_)

e$B$3$l$J$s$G$9$,!"\<h$j2\<$2$5$;$F$$$?$@$-$^$9!#e(B

class A  
def self.instance  
@a ||= new # e$B$3$3$Ge(B @a e$B$Oe(B Class  
e$B%/%i%9$N%$%s%9%?%s%9e(B A e$B$N%$%s%9%?%s%9JQ?te(B  
end  
end  
A.instance # =\> #\<A:0xb7ce833c\>  
A.instance # =\> #\<A:0xb7ce833c\>  
A.instance\_variables # =\> [“@a”]

e$B$H$$$&Iw$K$J$C$F$$$k$N$G;d$N4V0c$$$G$9$M!#e(B

# 

e$B8B$j$J$/AH$_9~$_$K6a$$%i%$%V%i%jFb$GI8=`E:IU%i%$%V%i%j$r;HMQ$9$k$H$$$&$N$b6Z$,0-$9$.$^$9$7$M!#e(B

e$B$?$@!"%=!\<%9%3!\<%I$K%3%a%s%H$OI,MWL5$$$G$7$g$&$+!)e(B

# e$B;d$N$h$&$JAF9z$b$N$,FI$\_4V0c$($J$$$?$a$K!#!#!#e(B

## e$B3X$Y$P3X$V$[$ICN$i$J$$$3$H$,=P$F$/$k$J$!!#e(B

e$B$h$m$7$/$\*4j$$$7$^$9!#e(B

* * *

[http://redmine.ruby-lang.org/issues/show/499](http://redmine.ruby-lang.org/issues/show/499)
