Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start here. #2

Open
jarodzz opened this issue Nov 15, 2012 · 3 comments
Open

start here. #2

jarodzz opened this issue Nov 15, 2012 · 3 comments

Comments

@jarodzz
Copy link

jarodzz commented Nov 15, 2012

Hi, all, @codereading/readers.

I'm reading thor, and here's my report and questions.

Given a task like this.

class Example < Thor
  desc "show example", "show example by how it works"
   def show
      puts "this is how it works"
   end
end

Here's how thor works.

  • when *class Example < Thor *, thor will register Example into namespaces.
    using:

    
    def inherited(klass)
    

    this method will be called, every time a subclass is inheriting Thor.

  • when * desc "", "", method_options*, thor will call class methods desc, method_options.
    using:

    
    def desc; ... ; end
    def method_options; ... ; end
    

    it will save desc, and options to instance variables, @desc, @method_options.

  • when ** def show **. thor will save show into array tasks[].
    using:

    
      def method_added(meth)
      

    it creates a task, and save current @desc, @method_options to the task,
    then add this new task into array tasks[]

  • when you call "thor example:show", thor will look for namespaces and task names.

    
    def find_class_and_task_by_namespace()
    

    once it find 1 namespace aka class, and 1 match task name inside that namespace.
    it create a instance, and instance.send(task_name, *args).

thanks

Jarodzzzzz

hope it helps some one who just started reading.

@adamakhtar
Copy link
Member

hey @gtjgtjgtj - just in case remember to write @codereading/readers so everyone is notified of your issue. Should only need to do it once when you create one.

@agis
Copy link

agis commented Nov 15, 2012

Also don't forget to format your messages, and more importantly the code you're pasting (see Github Flavored Markdown) 😃

@jarodzz
Copy link
Author

jarodzz commented Nov 16, 2012

re-formated. thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants