Method: Kernel#__main__
- Defined in:
- lib/mug/main.rb
#__main__ ⇒ Object
Compares the calling source filename with ‘$PROGRAM_NAME` (`$0`).
Returns a falsey value if the calling context is not in the ‘main’ file.
If called without a block, and the calling context is in the ‘main’ file, returns true.
If called with a block, and the calling context is in the ‘main’ file, the block is executed and the result is returned.
15 16 17 18 19 20 |
# File 'lib/mug/main.rb', line 15 def __main__ cloc = caller_locations(1, 1)[0] return if cloc.nil? return unless File.absolute_path($0) == cloc.absolute_path block_given? ? (yield) : true end |