Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.9k views
in Technique[技术] by (71.8m points)

ruby - How to add generators that respect alphabetical orders

I created a generator it generates some files and adds some content into a file; I want it to also respect the alphabetical order of names in the file.

Example is: when I want to generate a new action I'll run rails g new_action drying_clothes. This will generate files with content and write into an existing file. This file has actions like: Cooking Pottery Soaking.

If I currently run the generator the action/ name drying_clothes will be inserted after Soaking, how can I ensure it respects alphabetical order? Here's my code so far:

def add_action
  inject_into_file 'app/actions.yml',
                    "#{file_name}

                      category: new
"
end

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...