刚接触 ruby,目前看别人写的代码,感觉在调试上很没方向,有时候在一些代码上用 puts 能打印出我想要看的值,有时候加了 puts 无用。想问问各位前辈是怎么对程序进行调试的?想弄个方便的调试方法,来边调试边看程序。 对这里的帖子和资料还不熟,没找到关于调试的文章,在网上搜了一下,看到有提到 ruby-debug。但是没找到很适合我这种菜鸟级别学习安装的文章。这里的前辈能指点我一下,或者给我个连接看看么?
是不是安装这个需要按下面的步骤?
一 下载 ruby-debug-base 安装
二 再下载 ruby-debug-ide 安装
三 最后安装 ruby-debug
可以看看测试怎么写,如果目标明确的话,测试驱动开发是不错的选择 http://ruby-doc.org/stdlib-1.9.3/libdoc/test/unit/rdoc/Test/Unit/Assertions.html
#13 楼 @blacktulip 谢谢你的帮助,你发的这个链接是怎么安装和使用 pry 的介绍是吧,我在我的机器上用 执行了开头的两个命令,出现这样的信息,是不是表示我机器上还没有 pry?
C:\Sites\redmine-2.3.0>gem install pry pry-doc WARNING: Error fetching data: too many connection resets (http://production.s3. rubygems.org/specs.4.8.gz) Fetching: slop-3.4.4.gem (100%) Fetching: method_source-0.8.1.gem (100%) Fetching: win32console-1.3.2-x86-mingw32.gem (100%) Fetching: pry-0.9.12.2-i386-mingw32.gem (100%) Successfully installed slop-3.4.4 Successfully installed method_source-0.8.1 Successfully installed win32console-1.3.2-x86-mingw32 Successfully installed pry-0.9.12.2-x86-mingw32 Fetching: yard-0.8.6.2.gem (100%) Fetching: pry-doc-0.4.6.gem (100%) Successfully installed yard-0.8.6.2 Successfully installed pry-doc-0.4.6 6 gems installed Installing ri documentation for slop-3.4.4... Installing ri documentation for method_source-0.8.1... unable to convert "\xE2" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/method_source.rb, skipping Installing ri documentation for win32console-1.3.2-x86-mingw32... Installing ri documentation for pry-0.9.12.2-x86-mingw32... unable to convert "\xE2" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/pry/terminal.rb, skipping Installing ri documentation for yard-0.8.6.2... Installing ri documentation for pry-doc-0.4.6... unable to convert "\x8D" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/pry-doc/core_docs_18/object_types, skipping unable to convert "\x9A" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/pry-doc/core_docs_19/object_types, skipping unable to convert "\xED" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/pry-doc/core_docs_20/object_types, skipping Installing RDoc documentation for slop-3.4.4... Installing RDoc documentation for method_source-0.8.1... unable to convert "\xE2" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/method_source.rb, skipping Installing RDoc documentation for win32console-1.3.2-x86-mingw32... Installing RDoc documentation for pry-0.9.12.2-x86-mingw32... unable to convert "\xE2" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/pry/terminal.rb, skipping Installing RDoc documentation for yard-0.8.6.2... Installing RDoc documentation for pry-doc-0.4.6... unable to convert "\x8D" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/pry-doc/core_docs_18/object_types, skipping unable to convert "\x9A" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/pry-doc/core_docs_19/object_types, skipping unable to convert "\xED" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/pry-doc/core_docs_20/object_types, skipping
C:\Sites\redmine-2.3.0>rvm gemset use global 'rvm' 不是内部或外部命令,也不是可运行的程序 或批处理文件。
C:\Sites\redmine-2.3.0>
#28 楼 @luikore 路径下是有几个新生成的文件夹。
是安装的时候,开头出现的那句话 WARNING: Error fetching data: too many connection resets (http://production.s3. rubygems.org/specs.4.8.gz) 还有安装过程中出现的类似语句对整体有影响么?
unable to convert "\x8D" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/pry-doc/core_docs_18/object_types, skipping unable to convert "\x9A" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/pry-doc/core_docs_19/object_types, skipping unable to convert "\xED" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK for lib/pry-doc/core_docs_20/object_types, skipping
#36 楼 @_samqiu php 我没接触过,所以领会不深,我在一个 view 页面里面的代码头部加了一下你给的语句,报错信息如下:
Started GET "/wktime/edit?project_Id=2&startday=2013-04-21&tab=wktime&user_id=3" for 127.0.0.1 at 2013-07-16 11:34:56 +0800 Processing by WktimeController#edit as HTML Parameters: {"project_Id"=>"2", "startday"=>"2013-04-21", "tab"=>"wktime", "user_id"=>"3"} Current user: xwj (id=5) Rendered plugins/redmine_wktime/app/views/wktime/edit.html.erb within layouts/base (46.9ms) Completed 500 Internal Server Error in 297ms
ActionView::Template::Error (undefined local variable or method current_user' for #<#<Class:0x39bab70>:0x3ea60a8>):
1: <%= debug current_user %>
2:
3: <%= stylesheet_link_tag 'wk-time', :plugin => "redmine_wktime" %>
4:
plugins/redmine_wktime/app/views/wktime/edit.html.erb:1:in
plugins_redmine_wktime_app_views_wktime_edit_html_erb__393893685_32842176'
actionpack (3.2.13) lib/action_view/template.rb:145:in block in render'
activesupport (3.2.13) lib/active_support/notifications.rb:125:in
instrument'
actionpack (3.2.13) lib/action_view/template.rb:143:in `render'
你给的这句话的添加是不是有讲究的?