有没有能够解析XLS和XLSX文件的宝石?我找到了Spreadsheet和ParseExcel,但他们都不懂XLSX格式.
为什么没有列出一些rake任务rake -T?喜欢db:migrate:reset?我可以毫无问题地执行它,但为什么不在那里列出?有没有办法获得一个真正的rake任务完整列表?
% rake -T (in /home/zeus/projects/my_project) rake about # List versions of all Rails frameworks and the environment rake db:create # Create the database from config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config) rake db:drop # Drops the database for the current Rails.env (use db:drop:all to drop all databases) rake db:fixtures:load # Load fixtures into the current environment's database. rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false). rake …
我总是使用计数器来检查i==0循环中的第一个项目():
i = 0
my_array.each do |item|
if i==0
# do something with the first item
end
# common stuff
i += 1
end
Run Code Online (Sandbox Code Playgroud)
有没有更优雅的方法来做到这一点(也许是一种方法)?
我刚开始学习Ruby(第一次编程),并且有一个关于变量的基本语法问题,以及编写代码的各种方法.
克里斯派恩的"学会编程"教会我写一个像这样的基本程序......
num_cars_again= 2
puts 'I own ' + num_cars_again.to_s + ' cars.'
Run Code Online (Sandbox Code Playgroud)
这很好,但后来我偶然发现了ruby.learncodethehardway.com上的教程,并被教导写出像这样的精确程序......
num_cars= 2
puts "I own #{num_cars} cars."
Run Code Online (Sandbox Code Playgroud)
它们都输出相同的东西,但显然选项2是一个更短的方法.
是否有任何特殊原因我应该使用一种格式而不是另一种格式?
flickr api提供了一个发布日期作为unix时间戳一:" The posted date is always passed around as a unix timestamp, which is an unsigned integer specifying the number of seconds since Jan 1st 1970 GMT."
例如,这是日期' 1100897479'.如何使用Ruby on Rails格式化它?
在Ruby中,可以使用<<将值附加到现有数组:
a = []
a << "foo"
Run Code Online (Sandbox Code Playgroud)
但是,您是否还可以将键/值对附加到现有哈希?
h = {}
h << :key "bar"
Run Code Online (Sandbox Code Playgroud)
我知道你可以这样做:
h[:key] = ""
h[:key] << "bar"
Run Code Online (Sandbox Code Playgroud)
但那不是我想要的.
谢谢.
我不确定Ruby中C风格回调的最佳成语 - 或者是否有更好的东西(而不是像C).在C中,我会做类似的事情:
void DoStuff( int parameter, CallbackPtr callback )
{
// Do stuff
...
// Notify we're done
callback( status_code )
}
Run Code Online (Sandbox Code Playgroud)
什么是相当好的Ruby?基本上我想在"DoStuff"中遇到某个条件时调用传入的类方法
我有以下内容 Array = ["Jason", "Jason", "Teresa", "Judah", "Michelle", "Judah", "Judah", "Allison"]
如何为每个相同元素生成计数?
Where:
"Jason" = 2, "Judah" = 3, "Allison" = 1, "Teresa" = 1, "Michelle" = 1?
Run Code Online (Sandbox Code Playgroud)
或产生哈希在哪里:
Where:hash = {"Jason"=> 2,"Judah"=> 3,"Allison"=> 1,"Teresa"=> 1,"Michelle"=> 1}
我创建了一个Ruby项目,但在运行时bundle update,并bundle install返回一个错误:
Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0
Run Code Online (Sandbox Code Playgroud)
它的形象是:http://i.imgur.com/dZMhI11.png?1
我的gemfile是:
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.0'
group :development do
gem 'sqlite3', '1.3.8'
end
gem 'sass-rails', '4.0.0'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.0'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
Run Code Online (Sandbox Code Playgroud)