lib/zelda/base.rb in zelda-1.1.1 vs lib/zelda/base.rb in zelda-1.2.0
- old
+ new
@@ -1,26 +1,13 @@
module Zelda
# Abstract base class to provide common functionality of Zelda importer classes.
- # including method_missing magic to turn an @attributes hash into getters.
+ # Every key in the hash is turned into a method, returning the value.
class Base
def initialize(attributes={})
- @attributes = {}
-
- attributes.each do |key, value|
- @attributes[key.to_sym] = value
- end
- end
-
- attr_reader :attributes
-
- # Try both string keys and symbol keys in that order.
- def method_missing(method, *args, &block)
- if @attributes[method]
- return @attributes[method]
- elsif @attributes.key?(method)
- return nil
- else
- super(method, *args, &block)
+ attributes.each_pair do |key, value|
+ self.class.send(:define_method, key) do
+ value
+ end
end
end
end
end
\ No newline at end of file