Skip to content

Instantly share code, notes, and snippets.

@flynn1982
Created July 11, 2019 23:56
Show Gist options
  • Save flynn1982/cab5dff976d413db7c8262fb5bdef92f to your computer and use it in GitHub Desktop.
Save flynn1982/cab5dff976d413db7c8262fb5bdef92f to your computer and use it in GitHub Desktop.
Rails Custom Generator and Thor Example
class CoolFileGenerator < Rails::Generators::Base
def set_file_name
@file_name = "cool_file.rb"
end
def create_cool_file
body = ask "What should I write into the file?"
create_file @file_name, "Insert after me \n" + body
end
def add_more_coolness
insert_into_file @file_name, after: "Insert after me \n" do
content = ask "What more should I write into the file?"
content + "\n"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment