create a controller via a script .rb

Hello,

this should be a straightfoward question.
I was wondering how to do the equivalent of :
ruby script/generate controller MyNewController

from within a .rb file.
I would then want to call the .rb script from my rails application.
Thanks in advance

Hal

Solution :
#!/usr/bin/env ruby
class X
def test2
require File.dirname(__FILE__) + '/../config/boot'

require "#{RAILS_ROOT}/config/environment"
require 'rails_generator'
require 'rails_generator/scripts/generate'

   Rails::Generator::Scripts::Generate.new.run(['controller','dil'])

  end
end