creating task alias automatically #190

Closed
simrb opened this Issue Oct 26, 2011 · 0 comments

Comments

Projects
None yet
1 participant

simrb commented Oct 26, 2011

I have a method for showing the task name of alias and implementing the task alias.

class MyThor < Thor

desc "task_alias", "See the alias name of task"
def task_alias(output = true)
    old_names = MyThor.instance_methods(false)
    new_names = {}

    i = 1; 
    old_names.each do |name|
        key_name = ''
        name.to_s.split('_').each do |subname| key_name << subname[0] end
        begin
            raise if new_names.has_key? key_name
            new_names[key_name] = name
        rescue
            i++
            j = i
            key_name += j.to_s
            retry
        end
    end

    if output == true
        new_names.each do |k,v| puts "#{v} => #{k}" end
    else
        #this line, it not works, cannot finds the method map
        new_names.each do |k,v| map k => v.to_sym end
    end
end

end

Question 1
How to implement this method task_alias(false) when the MyThor.start is invoked, i need to use this alias of task.

Question 2
How can i use the map method in a customize method, such as the task_alias

simrb closed this Oct 27, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment