Module: Kernel
- Defined in:
- lib/tcravit_ruby_lib/on_execute.rb
Instance Method Summary collapse
-
#on_execute ⇒ Object
A bit of ruby hackery to enable the script to be run directly from the command line, as well as included into other code.
Instance Method Details
#on_execute ⇒ Object
A bit of ruby hackery to enable the script to be run directly from the command line, as well as included into other code. (Courtesy of elliottcable).
Example:
class MyApp
# ...
def start()
#...
end
end
on_execute do
MyApp.new().start()
end
42 43 44 45 46 47 |
# File 'lib/tcravit_ruby_lib/on_execute.rb', line 42 def on_execute calling_file = caller.first.split(':').first if File.(calling_file) == File.($0) yield end end |