Module: Zenlish::WClasses::IrregularVerbExtension

Defined in:
lib/zenlish/wclasses/irregular_verb_extension.rb

Instance Method Summary collapse

Instance Method Details

#forms(theForms) ⇒ Object

Parameters:

  • theForm (Hash{Symbol => String})


17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/zenlish/wclasses/irregular_verb_extension.rb', line 17

def forms(theForms)
  valid_symbols = %i[past_simple past_participle]
  actual_symbols = theForms.keys
  actual_symbols.each do |symb|
    raise StandardError, "Invalid verb form #{symb}" unless valid_symbols.include?(symb)
  end
  if actual_symbols.size < valid_symbols.size
    missing = valid_symbols.find { |symb| !actual_symbols.include?(symb) }
    raise StandardError, "Missing form #{missing}"
  end
  @forms = [nil, nil]
  @forms[0] = theForms[valid_symbols[0]]
  @forms[1] = theForms[valid_symbols[1]]
end

#init_extension(host) ⇒ Object

This callback when the module is extending an object. Purpose: to inject a number of instance variables in the host def extended(host)



12
13
14
# File 'lib/zenlish/wclasses/irregular_verb_extension.rb', line 12

def init_extension(host)
  host.instance_variable_set(:@forms, [])
end

#past_participleObject



36
37
38
# File 'lib/zenlish/wclasses/irregular_verb_extension.rb', line 36

def past_participle
  @forms.last
end

#past_simpleObject



32
33
34
# File 'lib/zenlish/wclasses/irregular_verb_extension.rb', line 32

def past_simple
  @forms.first
end