A facade object that acts as the extension point for linguistic modules for a single language. A single instance of an inflector is generated for an object that has been extended with a Linguistics language the first time the language is used.
The inflector's language code
The object the inflector is delegating for
Create a new inflector for obj
.
# File lib/linguistics/inflector.rb, line 19
def initialize( language_code, obj )
raise TypeError, "can't inflect for another inflector!" if
obj.is_a?( Linguistics::Inflector )
@language_code = language_code
@obj = obj
super()
end
Output a programmer-readable representation of the object suitable for debugging.
# File lib/linguistics/inflector.rb, line 66
def inspect
return "#<(%s-language inflector) for <%s:0x%0x> >" % [
self.language,
@obj.class,
@obj.object_id / 2
]
end
Return the english-language name of the language the inflector is delegating for.
# File lib/linguistics/inflector.rb, line 41
def language
::Linguistics::ISO639::LANGUAGE_CODES[ self.language_code.to_sym ][:eng_name]
end
Returns true
if either the inflector or the object it's
wrapping respond to the specified message
.
# File lib/linguistics/inflector.rb, line 48
def respond_to_missing?( message, include_priv=false )
return self.obj.respond_to?( message, include_priv )
end
Return the target object as an Integer
# File lib/linguistics/inflector.rb, line 60
def to_i
return self.obj.to_i
end
Return the target object as a String.
# File lib/linguistics/inflector.rb, line 54
def to_s
return self.obj.to_s
end
Delegate missing methods to the target object.
# File lib/linguistics/inflector.rb, line 80
def method_missing( sym, *args, &block )
return super unless self.obj.respond_to?( sym )
meth = self.obj.method( sym )
self.singleton_class.send( :define_method, sym, &meth )
return self.method( sym ).call( *args, &block )
end