Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Callable defaults #99

wants to merge 1 commit into from

5 participants


For dynamic defaults.


I think it would be better to do it like this:

options[key] = value.respond_to?(:call) ? : value

Since both a lambda and a Proc respond to call (plus any other Object the user could create that responds to call as well


This seems like a good feature but could you please add tests?




+1 on this. I would like to configure defaults for certain parameters to be read from environment variables (in my case AWS credentials.)

While this works by simply doing :default => ENV['FOO'] it can't be unit tested because by the time tests run, the Thor class is already configured since it was done at load time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 13, 2010
  1. @benburkert

    Add callable defaults.

    benburkert authored
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 0 deletions.
  1. +17 −0 lib/thor.rb
17 lib/thor.rb
@@ -331,4 +331,21 @@ def help(task = nil, subcommand = true); super; end
def help(task = nil, subcommand = false)
task ? self.class.task_help(shell, task) :, subcommand)
+ def initialize(*)
+ super
+ lazy_load_options!
+ end
+ no_task do
+ def lazy_load_options!
+ options =
+ @options.each do |key, value|
+ options[key] = (Proc === value ? : value)
+ end
+ @options = options
+ end
+ end
Something went wrong with that request. Please try again.