Class: Linguistics::LanguageProxyClass

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

Overview

Template class – is cloned and

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(receiver) ⇒ LanguageProxyClass

Create a new LanguageProxy for the given receiver.



65
66
67
# File 'lib/linguistics.rb', line 65

def initialize( receiver )
	@receiver = receiver
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object

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



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/linguistics.rb', line 82

def method_missing( sym, *args )
	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 )
end

Class Attribute Details

.langmodObject

Returns the value of attribute langmod.



60
61
62
# File 'lib/linguistics.rb', line 60

def langmod
  @langmod
end

Instance Method Details

#inspectObject

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



97
98
99
100
101
102
103
# File 'lib/linguistics.rb', line 97

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)


75
76
77
# File 'lib/linguistics.rb', line 75

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