Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Use fixed methods instead of method_missing.

AskForClass overrides method_missing and is included by commander/import
to allow you to do things like

  words_array = ask_for_array("Type some words")

and get a parsed array back.

Unfortunately, commander/import.rb includes AskForClass which
means Kernel#method_missing is overridden and performance suffers.

This fix replaces the method missing with a fixed number of defined
methods for each class that needs an ask_for_* method.

Initially only implements ask_for_array.
  • Loading branch information...
commit 85743ddcc902055cbfe9f1c3e11b774d366ff612 1 parent 601522c
Jonathon M. Abbott authored May 12, 2011

Showing 1 changed file with 3 additions and 4 deletions. Show diff stats Hide diff stats

  1. 7  lib/commander/user_interaction.rb
7  lib/commander/user_interaction.rb
@@ -291,10 +291,9 @@ def progress arr, options = {}, &block
291 291
     # Implements ask_for_CLASS methods.
292 292
     
293 293
     module AskForClass
294  
-      def method_missing meth, *args, &block
295  
-        case meth.to_s
296  
-        when /^ask_for_([\w]+)/ ; $terminal.ask(args.first, Kernel.const_get($1.capitalize))
297  
-        else super
  294
+      [Array].each do |klass|
  295
+        define_method "ask_for_#{klass.to_s.downcase}" do |prompt|
  296
+          $terminal.ask(prompt, klass)
298 297
         end
299 298
       end
300 299
     end

0 notes on commit 85743dd

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