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})


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

def forms(theForms)
  valid_symbols = [: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)



10
11
12
# File 'lib/zenlish/wclasses/irregular_verb_extension.rb', line 10

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

#past_participleObject



34
35
36
# File 'lib/zenlish/wclasses/irregular_verb_extension.rb', line 34

def past_participle
  @forms.last
end

#past_simpleObject



30
31
32
# File 'lib/zenlish/wclasses/irregular_verb_extension.rb', line 30

def past_simple
  @forms.first
end