Class: Zelda::Base
- Inherits:
-
Object
- Object
- Zelda::Base
- Defined in:
- lib/zelda/base.rb
Overview
Abstract base class to provide common functionality of Zelda importer classes. including method_missing magic to turn an @attrs hash into getters.
Direct Known Subclasses
Instance Method Summary collapse
- #attributes ⇒ Object
-
#initialize(attrs = {}) ⇒ Base
constructor
A new instance of Base.
-
#method_missing(method, *args, &block) ⇒ Object
Try both string keys and symbol keys in that order.
Constructor Details
#initialize(attrs = {}) ⇒ Base
Returns a new instance of Base.
5 6 7 |
# File 'lib/zelda/base.rb', line 5 def initialize(attrs={}) @attrs = attrs end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Try both string keys and symbol keys in that order.
14 15 16 17 18 19 20 21 22 |
# File 'lib/zelda/base.rb', line 14 def method_missing(method, *args, &block) if @attrs[method.to_s] return @attrs[method.to_s] elsif @attrs[method] return @attrs[method] else super(method, *args, &block) end end |
Instance Method Details
#attributes ⇒ Object
9 10 11 |
# File 'lib/zelda/base.rb', line 9 def attributes @attrs end |