我想使用Net :: HTTP 从WordPress.org下载latest.zip .这是我到目前为止所得到的:
Net::HTTP.start("wordpress.org/") { |http|
resp = http.get("latest.zip")
open("a.zip", "wb") { |file|
file.write(resp.body)
}
puts "WordPress downloaded"
}
Run Code Online (Sandbox Code Playgroud)
但这只给我一个4千字节的404错误HTML页面(如果我将文件更改为a.txt).我认为这与URL有关可能会以某种方式重定向但我不知道我在做什么.我是Ruby的新手.
我正在尝试在OSX上安装Visual Ruby.按照VisualRuby.net上的指南,我做了以下操作.
brew install gtk+
Run Code Online (Sandbox Code Playgroud)
然后:
brew install gtksourceview
Run Code Online (Sandbox Code Playgroud)
最后:
sudo gem install visualruby
Run Code Online (Sandbox Code Playgroud)
这会产生以下错误消息.我不知道出了什么问题,有什么想法吗?
Building native extensions. This could take a while...
ERROR: Error installing visualruby:
ERROR: Failed to build gem native extension.
/Users/ma/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for -Wall option to compiler... yes
checking for -Waggregate-return option to compiler... yes
checking for -Wcast-align option to compiler... yes
checking for -Wextra option to compiler... yes
checking for -Wformat=2 option to compiler... yes
checking for -Winit-self option to compiler... yes
checking for …Run Code Online (Sandbox Code Playgroud) 当我尝试使用Ruby-command尝试访问gem时运行我的.rb文件时,我遇到了问题.我试图使用的宝石是Ruby-Whois.我有一个示例脚本,当我尝试通过"ruby whois.rb"执行它时,我收到此错误消息:
./whois.rb:6:未初始化的常量Whois(NameError)
但是,如果我在IRB中逐行运行相同的脚本,我会得到预期的结果.可能是什么原因导致的
以下是whois.rb
require "rubygems"
require "whois"
domain = "google.com"
c = Whois::Client.new
a = c.query(domain)
puts a
Run Code Online (Sandbox Code Playgroud)