Evgenii Legotckoi
June 17, 2016, 10:50 p.m.

User Guide #02 - Ruby - Getting Started

First, you'll want to check whether ruby is installed. From the shell prompt (denoted here by "

  1. %
", so don't type the
  1. %
), type

  1. % ruby -v

( -v tells the interpreter to print the version of ruby), then press the Enter key. If ruby is installed, you will see a message something like the following:

  1. % ruby -v
  2. ruby 1.6.6 (2001-12-26) [i586-linux]

If ruby is not installed, you need to install it, since ruby is free software with no restrictions on its installation or use.


Now, let's play with ruby. You can place a ruby program directly on the command line using the -e option:

  1. % ruby -e 'print "hello world\n"'
  2. hello world

More conventionally, a ruby program can be stored in a file.

  1. % cat > test.rb
  2. print "hello world\n"
  3. ^D
  4. % cat test.rb
  5. print "hello world\n"
  6. % ruby test.rb
  7. hello world

  1. ^D
is control-D . The above is just for UNIX. If you're using DOS, try this:

  1. C:\ruby> copy con: test.rb
  2. print "hello world\n"
  3. ^Z
  4. C:\ruby> type test.rb
  5. print "hello world\n"
  6. C:\ruby> ruby test.rb
  7. hello world

When writing more substantial code than this, you will want to use a real text editor!

Some surprisingly complex and useful things can be done with miniature programs that fit in a command line. For example, this one replaces

  1. foo
with
  1. bar
in all C source and header files in the current working directory, backing up the original files with ".bak" appended:

  1. % ruby -i.bak -pe 'sub "foo", "bar"' *.[ch]

This program works like the UNIX

  1. cat
command (but works slower than
  1. cat
):

  1. % ruby -pe 0 file

Do you like it? Share on social networks!

Comments

Only authorized users can post comments.
Please, Log in or Sign up
  • Last comments
  • Evgenii Legotckoi
    April 16, 2025, 5:08 p.m.
    Благодарю за отзыв. И вам желаю всяческих успехов!
  • IscanderChe
    April 12, 2025, 5:12 p.m.
    Добрый день. Спасибо Вам за этот проект и отдельно за ответы на форуме, которые мне очень помогли в некоммерческих пет-проектах. Профессиональным программистом я так и не стал, но узнал мно…
  • AK
    April 1, 2025, 11:41 a.m.
    Добрый день. В данный момент работаю над проектом, где необходимо выводить звук из программы в определенное аудиоустройство (колонки, наушники, виртуальный кабель и т.д). Пишу на Qt5.12.12 поско…
  • Evgenii Legotckoi
    March 9, 2025, 9:02 p.m.
    К сожалению, я этого подсказать не могу, поскольку у меня нет необходимости в обходе блокировок и т.д. Поэтому я и не задавался решением этой проблемы. Ну выглядит так, что вам действитель…
  • VP
    March 9, 2025, 4:14 p.m.
    Здравствуйте! Я устанавливал Qt6 из исходников а также Qt Creator по отдельности. Все компоненты, связанные с разработкой для Android, установлены. Кроме одного... Когда пытаюсь скомпилиров…