Class: Dragonfly::Register
Defined Under Namespace
Classes: NotFound
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
- #add(name, item = nil, &block) ⇒ Object
- #get(name) ⇒ Object
-
#initialize ⇒ Register
constructor
A new instance of Register.
- #names ⇒ Object
Constructor Details
#initialize ⇒ Register
Returns a new instance of Register.
7 8 9 |
# File 'lib/dragonfly/register.rb', line 7 def initialize @items = {} end |
Instance Attribute Details
#items ⇒ Object (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 |
#names ⇒ Object
21 22 23 |
# File 'lib/dragonfly/register.rb', line 21 def names items.keys end |