Class: Linguistics::LanguageProxyClass

Inherits:
Object
  • Object
show all
Defined in:
lib/linguistics.rb

Overview

A class which is inherited from by proxies for classes being extended with one or more linguistic interfaces. It provides on-the-fly creation of linguistic methods when the :installProxy option is passed to the call to Linguistics#use.

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(receiver) ⇒ LanguageProxyClass

Create a new LanguageProxy for the given receiver.



72
73
74
# File 'lib/linguistics.rb', line 72

def initialize( receiver )
	@receiver = receiver
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Autoload linguistic methods defined in the module this object’s class uses for inflection.



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/linguistics.rb', line 89

def method_missing( sym, *args, &block )
	return super unless self.class.langmod.respond_to?( sym )

	self.class.module_eval %{
		def #{sym}( *args, &block )
			self.class.langmod.#{sym}( @receiver, *args, &block )
		end
	}, "{Autoloaded: " + __FILE__ + "}", __LINE__

	self.method( sym ).call( *args, &block )
end

Class Attribute Details

.langmodObject

Returns the value of attribute langmod.



67
68
69
# File 'lib/linguistics.rb', line 67

def langmod
  @langmod
end

Instance Method Details

#inspectObject

Returns a human-readable representation of the languageProxy for debugging, logging, etc.



104
105
106
107
108
109
110
# File 'lib/linguistics.rb', line 104

def inspect
	"<%s languageProxy for %s object %s>" % [
		self.class.langmod.language,
		@receiver.class.name,
		@receiver.inspect,
	]
end

#respond_to?(sym) ⇒ Boolean

Overloaded to take into account the proxy method.

Returns:

  • (Boolean)


82
83
84
# File 'lib/linguistics.rb', line 82

def respond_to?( sym )
	self.class.langmod.respond_to?( sym ) || super
end