Class: Coursemology::Polyglot::Language

Inherits:
Object
  • Object
show all
Defined in:
lib/coursemology/polyglot/extensions/language.rb

Class Method Summary collapse

Class Method Details

.find_by(type:) ⇒ nil, Class

Finds the language class with the specified name.

Parameters:

  • type (String)

    The name of the class.

Returns:

  • (nil)

    If the type is not defined.

  • (Class)

    If the type was found.



8
9
10
11
# File 'lib/coursemology/polyglot/extensions/language.rb', line 8

def self.find_by(type:)
  class_ = concrete_languages.find { |language| language.name == type }
  class_.new if class_
end

.find_by!(type:) ⇒ Class

Finds the language class with the specified name.

Parameters:

  • type (String)

    The name of the class.

Returns:

  • (Class)

    If the type was found.

Raises:

  • (ArgumentError)

    When the type was not found.



18
19
20
21
22
23
# File 'lib/coursemology/polyglot/extensions/language.rb', line 18

def self.find_by!(type:)
  language = find_by(type: type)
  fail ArgumentError, "Cannot find the language #{type}" unless language

  language
end