Skip to content
Browse files

add to_lang magic methods

  • Loading branch information...
1 parent d08f68d commit 4c26f80bba90a955540b4d9cc1f3538371f1efa5 @jimmycuadra jimmycuadra committed Dec 25, 2010
Showing with 23 additions and 0 deletions.
  1. +23 −0 lib/to_lang.rb
View
23 lib/to_lang.rb
@@ -8,6 +8,29 @@ class << self
def start(key)
@connector = ToLang::Connector.new(key)
String.send(:include, StringMethods)
+ add_magic_methods
+ end
+
+ private
+
+ def add_magic_methods
+ String.class_eval do
+ def method_missing(method, *args, &block)
+ if method.to_s =~ /^to_(.*)$/ && CODEMAP[$1]
+ self.translate(CODEMAP[$1])
+ else
+ super
+ end
+ end
+
+ def respond_to?(method, include_private = false)
+ if method.to_s =~ /^to_(.*)$/ && CODEMAP[$1]
+ true
+ else
+ super
+ end
+ end
+ end
end
end

0 comments on commit 4c26f80

Please sign in to comment.
Something went wrong with that request. Please try again.