Class: Dragonfly::Register

Inherits:
Object show all
Defined in:
lib/dragonfly/register.rb

Defined Under Namespace

Classes: NotFound

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegister

Returns a new instance of Register.



7
8
9
# File 'lib/dragonfly/register.rb', line 7

def initialize
  @items = {}
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



11
12
13
# File 'lib/dragonfly/register.rb', line 11

def items
  @items
end

Instance Method Details

#add(name, item = nil, &block) ⇒ Object



13
14
15
# File 'lib/dragonfly/register.rb', line 13

def add(name, item=nil, &block)
  items[name.to_sym] = item || block || raise(ArgumentError, "you must give either an argument or a block")
end

#get(name) ⇒ Object



17
18
19
# File 'lib/dragonfly/register.rb', line 17

def get(name)
  items[name.to_sym] || raise(NotFound, "#{name.inspect} not registered")
end

#namesObject



21
22
23
# File 'lib/dragonfly/register.rb', line 21

def names
  items.keys
end