Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Faster method, the regex / gsub overhead is invoked only the first time, then an alias is used. I'm not sure that this wouldn't introduce side-effects however. What happens when the original camel-cased method is changed / removed, but it's alias remains inplace?
- class Object
- alias orig_method_missing method_missing
- def method_missing name, *args, &block
- if name =~ /\A[a-z\d_]+\z/
- camel_name = name.gsub(/_(.)/) { $1.upcase }
- if self.respond_to? camel_name
- # The 'rescue nil' is because macruby seems to do some odd things with classes sometimes (SBElementArray?):
- self.class.send :alias_method, name, camel_name rescue nil
- return self.send camel_name, *args, &block
- end
- end
- orig_method_missing
- end
- end
Add Comment
Please, Sign In to add comment