一.Bundler
Bundler 能够跟踪并安装所需的特定版本的 gem,以此来为 Ruby 项目提供一 致的运行环境.

source 'https://rubygems.org'
gem 'rails', '4.1.0.rc2'
gem ‘rack-cache'
gem 'nokogiri', '~> 1.6.1'
二.插件安装
安装VSCode的Ruby插件

3.安装调试工具
ruby-debug-ide
ruby-debug-ide提供了交互环境。和IDE(例如RubyMine,Visual Studio Code或 Eclipse)之间建立通信的协议。“ ruby -debug-ide”将命令从IDE重定向到调试器。然 后,它将从调试器收到的答案/事件返回给IDE。
gem install ruby-debug-ide
debase
debase是针对Ruby 2.0的标准Ruby调试器debug.rb的快速实现。它是通过利用新的 Ruby TracePoint类实现的。核心组件提供了前端可以建立的支持。它提供断点处理, 堆栈信息等。
gem 'debase'
三.调试
1.创建空文件夹TestRuby

2.创建main.rb文件
在TestRuby目录新建一个ruby的源码文件main.rb
touch main.rb
3.创建gemfile
在TestRuby目录新建gemfile
touch gemfile
在gemfile输入以下内容
source 'https://rubygems.org'
gem 'ruby-debug-ide'
gem 'debase'
4.创建 launch.json
在TestRuby目录下创建.vscode目录,然后在 .vscode 里面再创建一个名字叫 launch.json 的文件,文件里面输入下面的内容。
{
"configurations": [
{
"name": "Debug CocoaPods Plugin with Bundler",
"showDebuggerOutput": true,
"type": "Ruby",
"request": "launch",
"useBundler": true,
"cwd": "${workspaceRoot}", //cwd代表运行的目录,发现好像必须和gemfile一个目录。${workspaceRoot}指的是VSCode工程的目录。你也可以指定一个绝对路径
"program": "${workspaceRoot}/main.rb", //运行的ruby代码
"stopOnEntry": false
}
]
}
5.打开终端,cd到TestRuby目录下,输入下面命令。
bundle install

6.用VSCode打开TestRuby目录
7.在VSCode里面打开我们的main.rb,然后在行号左边单击下断点


网友评论