title: Dynamically loading Thor options for a Ruby Gem
body: <p>While trying to develop a simple gem to learn the process, I happened to stumble on this issue: <em>Thor</em> DSL takes in <em>options</em> to a <em>command</em> using the syntax: <code>option :some_option, :type =&gt; :boolean</code>, just prior to the method definition.</p>
  
  <p>I am trying to have a dynamic set of options loaded from a file. I do this file read operation in the constructor, but it seems the <code>option</code> keyword for the <em>Thor</em> class is getting processed before the <code>initialize</code> method.</p>
  
  <p>Any ideas to resolve this? Also it would be great if someone can explain how the option keyword works? I mean is <code>option</code> a method call? I don't get the design. (This is the first DSL I am trying out and am a total newbie to Ruby Gems)</p>
  
  <pre><code>#!/usr/bin/env ruby
  
  require 'thor'
  require 'yaml'
  require 'tinynews'
  
  class TinyNewsCLI &lt; Thor
    attr_reader :sources
    @sources = {}
  
    def initialize *args
      super
      f = File.open( "sources.yml", "r" ).read
      @sources = YAML::load( f )
    end
  
    desc "list", "Lists the available news feeds."
    def list
      puts "List of news feed sources: "
      @sources.each do |symbol, source|
        puts "- #{source[:title]}"
      end
    end
  
    desc "show --source SOURCE", "Show news from SOURCE feed"
    option :source, :required =&gt; true
    def show
      if options[:source]
        TinyNews.print_to_cli( options[:source].to_sym )
      end
    end
  
    desc "tinynews --NEWS_SOURCE", "Show news for NEWS_SOURCE"
    @sources.keys.each do |source_symbol| # ERROR: States that @sources.keys is nil
      #[:hindu, :cnn, :bbc].each do |source_symbol| # I expected the above to work like this
      option source_symbol, :type =&gt; :boolean
    end
    def news_from_option
      p @sources.keys
      TinyNews.print_to_cli( options.keys.last.to_sym )
    end
  
    default_task :news_from_option
  
  end
  
  TinyNewsCLI.start( ARGV )
  </code></pre>