class GreeterFactory

The GreeterFactory is an implementation of the Simple Factory Pattern. It allows you to create instances of the ::Greeter class by calling the ::create class method.

Public Class Methods

available_languages() click to toggle source

Get all the language names that are available for creating greeter objects.

Returns

An array with the name of the languages.

# File src/models/greeter_factory.rb, line 20
def self.available_languages
  @@greetings.keys
end
create(language) click to toggle source

Creates a new greeter object.

Parameter
language

The language for the greeter object that will be created.

Returns

The newly created greeter object.

Raises

ArgumentError if language is unknown.

# File src/models/greeter_factory.rb, line 33
def self.create(language)
  raise ArgumentError.new("Unknow language: '#{ language}'")        if !@@greetings.key?(language)
  Greeter.new(language, @@greetings[language])
end