Class: Wayback::Factory
- Inherits:
-
Object
- Object
- Wayback::Factory
- Defined in:
- lib/wayback/factory.rb
Class Method Summary collapse
-
.fetch_or_new(method, klass, attrs = {}) ⇒ Wayback::Action::Favorite, ...
Instantiates a new action object.
Class Method Details
.fetch_or_new(method, klass, attrs = {}) ⇒ Wayback::Action::Favorite, ...
Instantiates a new action object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/wayback/factory.rb', line 9 def self.fetch_or_new(method, klass, attrs={}) return unless attrs type = attrs.delete(method.to_sym) if type const_name = type.gsub(/\/(.?)/){"::#{$1.upcase}"}.gsub(/(?:^|_)(.)/){$1.upcase} klass.const_get(const_name.to_sym).fetch_or_new(attrs) else raise ArgumentError, "argument must have :#{method} key" end end |