Skip to content

Commit f105f9a

Browse files
committed
use memoization instead of checking attribute explicitly
1 parent ea778a5 commit f105f9a

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

singleton.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ class HeroFactory
33
@@instance = nil
44

55
def self.instance
6-
@@instance = HeroFactory.send(:new) unless @@instance
7-
@@instance
6+
@@instance ||= HeroFactory.send(:new)
87
end
98

109
def create_warrior

0 commit comments

Comments
 (0)