起步

    起步

    First, you’ll want to check whether ruby is installed. From the shell prompt (denoted here by “%”, so don’t type the %), type

    首先,如果你想检测Ruby是否已经安装,在提示符中输入:

    (-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:

    (表示让解释器打印出当前Ruby的版本)

    然后按下回车键。如果Ruby已经安装,你将会看到类似下面这样的信息:

    如果Ruby还没有安装,那么你可以选择自己动手安装,或者向计算机管理员寻求帮助。Ruby是一个自由软件,任何人都可以随意安装和使用。

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

    现在,让我们来把玩一下Ruby。你可以在命令行中用选项来直接执行Ruby程序。

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

    更传统一点,Ruby程序可以被保存在文件中。

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

    你编写的代码量远超上面的示例时,你可能想到是时候使用一个文本编辑器了。

    命令行中的小程序可以用来完成一些非常复杂和有用的操作。

    For example, this one replaces foo with bar in all C source and header files in the current working directory, backing up the original files with “.bak” appended:

    举个例子,这个程序会将当前目录中的C语言源文件头文件中的foo替换为bar

    This program works like the UNIX cat command (but works slower than cat):

    而这个程序的作用则有点像UNIX中的cat命令(但是处理过程比cat慢)。