Class: Linguistics::Latin::Verb::LatinVerb::Mutators::Deponent::TenseBlockMutator
- Inherits:
-
Object
- Object
- Linguistics::Latin::Verb::LatinVerb::Mutators::Deponent::TenseBlockMutator
- Defined in:
- lib/latinverb/tense_method_applicator/mutators/deponent/tense_block_mutator.rb
Instance Method Summary collapse
-
#initialize(verb, proxyVerb) ⇒ TenseBlockMutator
constructor
A new instance of TenseBlockMutator.
-
#mutate! ⇒ Object
Swaps this verb’s active_ vectors and replaces them with @proxyVerb’s passive_ vectors.
Constructor Details
#initialize(verb, proxyVerb) ⇒ TenseBlockMutator
Returns a new instance of TenseBlockMutator.
8 9 10 11 12 13 |
# File 'lib/latinverb/tense_method_applicator/mutators/deponent/tense_block_mutator.rb', line 8 def initialize(verb, proxyVerb) @verb = verb @proxyVerb = proxyVerb mutate! end |
Instance Method Details
#mutate! ⇒ Object
Swaps this verb’s active_ vectors and replaces them with @proxyVerb’s passive_ vectors. This is pretty darned sneaky. See Also deponent_swap
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/latinverb/tense_method_applicator/mutators/deponent/tense_block_mutator.rb', line 22 def mutate! # First, get the methods that were defined in the proxy as passive storage = {} @proxyVerb.methods.grep(/\Apassive.+tense\z/).each do |pass| # Find the active correlate active_corr = pass.to_s.sub( /^passive(.*)/, "active\\1" ) # Keep @proxyVerb in the binding scope pV = @proxyVerb # In verb, find the passive and save its resultant object into a # hash for future use. @verb.instance_eval do storage[active_corr.to_sym] = pV.send(pass) end end # Take the stored hashes and define instance methods on verb such # that we intercept the mixed-in methods ( C-c-c-combo breaker! ). storage.each_pair do |k,v| @verb.singleton_class.class_eval do define_method k, Proc.new { return v } end end end |