Class: Gamefic::Grammar::Verbs

Inherits:
Object
  • Object
show all
Extended by:
Conjugator::ClassMethods
Defined in:
lib/gamefic/grammar/verbs.rb

Instance Method Summary collapse

Methods included from Conjugator::ClassMethods

conjugate, conjugated_verbs

Constructor Details

#initialize(obj) ⇒ Verbs

Returns a new instance of Verbs.



7
8
9
10
11
12
13
14
# File 'lib/gamefic/grammar/verbs.rb', line 7

def initialize obj
  @pronoun = obj
  self.class.conjugated_verbs.each_pair { |infinitive, verbset|
    define_singleton_method infinitive do
      verbset[:present].conjugate @pronoun
    end
  }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(infinitive, *args, &block) ⇒ Object



15
16
17
# File 'lib/gamefic/grammar/verbs.rb', line 15

def method_missing infinitive, *args, &block
  Gamefic::Grammar::VerbSet.new(infinitive, nil, *args).conjugate(@pronoun)
end

Instance Method Details

#[](infinitive) ⇒ Object



18
19
20
21
# File 'lib/gamefic/grammar/verbs.rb', line 18

def [] infinitive
  words = infinitive.split_words
  Gamefic::Grammar::VerbSet.new(words[0], nil).conjugate(@pronoun) + (words.length > 1 ? ' ' + words[1..-1].join(' ') : '')
end