Run a Ruby library from the command-line -


I have learned the basics of Ruby after being very happy with Python for many years (I still use Python I'm a few things), but I want to know if there is an idiom or hack to solve this problem.

I have a Ruby script that I want to be able to do with script_name is required , but I can convert ruby ​​script_name to rb from the terminal I want to be able to run and it is run as a command line script in Python, it will be done in the lower part of the script by the following structure:

  if __name__ == '__main__' : # Do something here  

However, in Ruby I Can not find an equivalent, is there a way to find out whether the current script is being run from the command line or not? Maybe some kernel :: method or something else? Ideally what I want is that there is something like this in the lower part of the script:

  if if by_command_line? # You can find a similar functionality in Ruby  

__ file __ The name of the current source file. The name of the script

$ 0 has been executed. May be assigned can be.

Source:


Comments