Class: Twitter::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter/factory.rb

Direct Known Subclasses

GeoFactory, MediaFactory

Class Method Summary (collapse)

Class Method Details

+ (Twitter::Base) new(method, klass, attrs = {})

Construct a new object

Raises:

  • (IndexError)

    Error raised when supplied argument is missing a key.



11
12
13
14
15
# File 'lib/twitter/factory.rb', line 11

def new(method, klass, attrs = {})
  type = attrs.fetch(method.to_sym)
  const_name = type.gsub(/\/(.?)/) { "::#{Regexp.last_match[1].upcase}" }.gsub(/(?:^|_)(.)/) { Regexp.last_match[1].upcase }
  klass.const_get(const_name.to_sym).new(attrs)
end