如何在Win7上调试Ruby程序

Python043

如何在Win7上调试Ruby程序,第1张

先安装rubyinstaller,下载并解压DevKit,注意,这两个版本要对应,网页上有说明(http://rubyinstaller.org/downloads/),解压DevKit后,打开目录,运行devkitvars.bat(是不是必须的不确定)。

打开cmd,进入DevKit的解压目录

ruby dk.rb

---

Configures an MSYS/MinGW based Development Kit (DevKit) for

each of the Ruby installations on your Windows system. The

DevKit enables you to build many of the available native

RubyGems that don't yet have a binary gem.

Usage: ruby dk.rb COMMAND [options]

where COMMAND is one of:

init prepare DevKit for installation

review review DevKit install plan

install install required DevKit executables

and 'install' [options] are:

-f, --force overwrite existing helper scripts

-------------

ruby dk.rb init

---

Initialization complete! Please review and modify the auto-generated

'config.yml' file to ensure it contains the root directories to all

of the installed Rubies you want enhanced by the DevKit.

--------------------------------

ruby dk.rb install

---

Invalid configuration or no Rubies listed. Please fix 'config.yml'

and rerun 'ruby dk.rb install'

如果出现的是这个,则需要修改config.yml

加入

- C:\Ruby200-x64

---

[INFO] Updating convenience notice gem override for 'C:/Ruby200-x64'

[INFO] Installing 'C:/Ruby200-x64/lib/ruby/site_ruby/devkit.rb'

这是对的

---------------------

gem install ruby-debug-ide

---

Temporarily enhancing PATH to include DevKit...

Building native extensions. This could take a while...

Successfully installed ruby-debug-ide-0.4.17

Parsing documentation for ruby-debug-ide-0.4.17

Installing ri documentation for ruby-debug-ide-0.4.17

1 gem installed

在TestRuby目录新建一个ruby的源码文件main.rb

在TestRuby目录新建gemfile

在gemfile输入以下内容

在TestRuby目录下创建.vscode目录,然后在 .vscode 里面再创建一个名字叫 launch.json 的文件,文件里面输入下面的内容。

ruby安装完之后,打开文本编辑器,在Window系统就是记事本,输入,

print("Hello,Ruby!\n")

点击文件,选择另存为,这里保存在桌面,文件的名字改为helloruby.rb

点击开始运行,输入cmd,打开命令提示符,

然后返回桌面,点击刚才保存的文件,右键属性,

找到位置,点击复制。

返回cmd,输入cd C:\Documents and Settings\Administrator\桌面(这个是我刚才文件保存的路径,具体情况自己分析)

现在输入刚才在记事本写入的代码文件的名称helloruby.rb

看到了么,倒数的第二行,显示了“Hello,Ruby!”,虽然只有一行代码,但是对于Ruby编程是合法的,"Hello,Ruby!\n"就是ruby的字符串。