Welcome to WebmasterServe!

FREE TO JOIN! Join us now to engage in informative and friendly discussions about Webmastering, SEO, SEM, Internet Marketing, Programming, Graphic Design, Online Jobs and more. What are you waiting for? Ready to join our friendly community? It takes just one minute to register.

Dismiss Notice

Join WebmasterServe Forums 
Join the discussion! Have a better idea or an opinion? It takes just one minute to register Click Here to Join

Help Me/Question What Are Your Favorite Commands To Execute Ruby Programs

Discussion in 'Ruby Programming' started by jazzvaga, Jan 3, 2016.

  1. jazzvaga

    Yellow Belt

    Joined:
    Jan 1, 2016
    Messages:
    191
    Ratings:
    +19 / -0
    Guys,

    What methods / commands / execution functions you use to deal with your code in Ruby Language?

    Anything specific here or you simply code it in a normal sequence!
     
  2. Oldwriter

    Yellow Belt

    Joined:
    Dec 10, 2015
    Messages:
    64
    Ratings:
    +28 / -0
    Hello @jazzvaga@jazzvaga,

    Do you mean what are the command-line switches to use Ruby?

    If you want to test a one-liner you can do it with the -e switch, with the format:

    ruby -e '<your code here>'

    for instance:

    Code:
    Select All
    ruby -e 'puts "Hello WebmasterServe"'
    If you want to interpret your program, you simply pass it to ruby in the command line:

    ruby <your program's file path here>

    Say you saved your program as the file wms.rb

    Code:
    Select All
    puts "Hello WebmasterServe"


    You would run it like:
    Code:
    Select All
    ruby wms.rb
    If you want to execute your program directly as any other program in your box, then you would add a shebang + ruby's interpreter path as your program's first line:

    Code:
    Select All
    #!/usr/bin/ruby puts "Hello WebMasterServe"
    Then give it execution permission with CHMOD:
    Code:
    Select All
    chmod +x wms.rb
    And finally run it as you would do with any other program:
    Code:
    Select All
    ./wms.rb
     
    #2 Oldwriter, Jan 15, 2016 at 4:19 PM
    Last edited: Jan 15, 2016

Share This Page