lib/device.rb in narou-1.0.2 vs lib/device.rb in narou-1.1.0.rc1

- old
+ new

@@ -23,9 +23,17 @@ def self.exists?(device) DEVICES.include?(device.downcase) end + def self.create(device_name) + @@device_cache ||= {} + name = device_name.downcase + return @@device_cache[name] ||= new(name) + end + + private_class_method :new + def initialize(device_name) unless Device.exists?(device_name) raise UnknownDevice, "#{device_name} は存在しません" end @device = DEVICES[device_name.downcase]