如何在Win7上调试Ruby程序

Python014

如何在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

我写了个程序 你看一下 不明白的话联系我 有注释

#获取当前的时间

today = Time.new

puts "当前日期:" + today.strftime("%Y-%m-%d %H:%M:%S")#采用格式化输出

#获取指定日期的时间 如 2010-08-30 20:50:01

day = Time.local(2010, 8 , 30 , 20, 50, 1)

puts "指定日期:" + day.strftime("%Y-%m-%d %H:%M:%S")

#获取指定日期的秒数(就是1970年到指定日期的秒数)

sec1 = day.to_i

#同理,获取今天的秒数

sec2 = today.to_i

#秒数求差,同时折合为天数

num = (sec1 - sec2)/(24*60*60)

puts (day.strftime("%Y-%m-%d %H:%M:%S") + "与" + today.strftime("%Y-%m-%d %H:%M:%S") + "相差" + num.to_s + "天")

这种脚本语言做大型计算,计算能力肯定是不太够的,一般都依赖于其它语言编写的高性能计算的库,比如python就有numpy/scipy/pandas/matplotlib等一系列库,这使得python比较适合进行大型科学计算,ruby也有相当的库sciruby,不过成熟度还不太够,sciruby官网上的说法是,这个库已经经过了测试,但是还没有经过实战的检验,在使用中要有可能会遇到bug的心理预期。原话如下:

Word to the wise: These gems have been tested, but are not battle-hardened. If you’re thinking of using NMatrix (or other SciRuby components) to write mission critical code, such as for a self-driving car or controlling an ARKYD 100 satellite, you should expect to encounter a few bugs — and be prepared for them.