How to implement rails generate command from scratch

How can I implement a ruby program that I can run from the command line without specifying file extension or running it like this ./my_program.rb

I would like to run my program from the command line like this: my_program [options]

It is similar to what you would do in rails:

rails generate [options] or

rails new [options]