okkez $B$G$9!#(B
lib/rubygems/command_manager.rb $B$GDj5A$5$l$F$$$k(B
Gem::CommandManager $B%/%i%9$G$9$,!"%=!<%9%3!<%I$rFI$s$G$_$?8B$j$G$O(B
singleton $B$K$7$?$+$C$?$N$8$c$J$$$+$H;W$&$N$G$9$,$$$+$,$G$7$g$&$+!)(B
$B85$N%3!<%I$@$H(B Gem::CommandManager.instance
$B$GKh2s?7$7$$%$%s%9%?%s%9(B
$B$,@8@.$5$l$^$9!#(B
$B=$@5$K$"$o$;$F%F%9%H$b=$@5$7$F$_$^$7$?!#(B
$B$h$m$7$/$*4j$$$7$^$9!#(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,
on 26.08.2008 10:31
on 03.09.2008 04:35
$B%A%1%C%H(B #499 $B$,99?7$5$l$^$7$?!#(B (by okkez _)
$B$3$l$J$s$G$9$,!"<h$j2<$2$5$;$F$$$?$@$-$^$9!#(B
class A
def self.instance
@a ||= new # $B$3$3$G(B @a $B$O(B Class
$B%/%i%9$N%$%s%9%?%s%9(B A $B$N%$%s%9%?%s%9JQ?t(B
end
end
A.instance # => #<A:0xb7ce833c>
A.instance # => #<A:0xb7ce833c>
A.instance_variables # => ["@a"]
$B$H$$$&Iw$K$J$C$F$$$k$N$G;d$N4V0c$$$G$9$M!#(B
#
$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!#(B
$B$?$@!"%=!<%9%3!<%I$K%3%a%s%H$OI,MWL5$$$G$7$g$&$+!)(B
# $B;d$N$h$&$JAF9z$b$N$,FI$_4V0c$($J$$$?$a$K!#!#!#(B
## $B3X$Y$P3X$V$[$ICN$i$J$$$3$H$,=P$F$/$k$J$!!#(B
$B$h$m$7$/$*4j$$$7$^$9!#(B
----------------------------------------
http://redmine.ruby-lang.org/issues/show/499