File: factory.rb

package info (click to toggle)
ruby-twitter 7.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 4,840 kB
  • sloc: ruby: 10,919; makefile: 6
file content (18 lines) | stat: -rw-r--r-- 519 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
module Twitter
  class Factory
    class << self
      # Construct a new object
      #
      # @param method [Symbol]
      # @param klass [Class]
      # @param attrs [Hash]
      # @raise [IndexError] Error raised when supplied argument is missing a key.
      # @return [Twitter::Base]
      def new(method, klass, attrs = {})
        type = attrs.fetch(method.to_sym)
        const_name = type.split('_').collect(&:capitalize).join
        klass.const_get(const_name.to_sym).new(attrs)
      end
    end
  end
end