30得票3回答
AWS弹性Beanstalk - 如何将现有环境从Ruby 2.1升级到Ruby 2.2

AWS Elastic Beanstalk - 无法从 Ruby 2.1 升级到 Ruby 2.2,也无法使用最新平台克隆或通过 eb 升级 我一直在为这个问题苦恼。 AWS 在五月份宣布他们的 Ruby 弹性环境现在提供 Ruby-2.2 (例如:ruby-2.2-(passenger-s...

17得票2回答
如何在Ruby中使用哈希值构建包含查询参数的URI

如何通过传递哈希来构造带有查询参数的URI对象? 我可以使用以下代码生成查询语句: URI::HTTPS.build(host: 'example.com', query: "a=#{hash[:a]}, b=#{[hash:b]}") 它将生成: https://example.co...

14得票3回答
红宝石块内的纤维异步不起作用

尝试在我的工作示例中实现 Celluloid 异步似乎表现出奇怪的行为。这是我的代码: class Indefinite include Celluloid def run! loop do [1].each do |i| ...

13得票3回答
Ruby中的关键字参数展开(splat)

下面发生的事情对我来说有点奇怪。def f(a, b) puts "#{a} :: #{b}" end f(*[1, 2], **{}) # prints "1 :: 2" hash = {} f(*[1, 2], **hash) ArgumentError: wrong number...

12得票2回答
Ruby 2中的日期时间减法?

我需要减去两个DateTime对象,以便找出它们之间的小时差。 我尝试做以下操作:a = DateTime.new(2015, 6, 20, 16) b = DateTime.new(2015, 6, 21, 16) puts a - b 我得到了(-1/1),它是一个Rational类的对象...

11得票1回答
单例模式无法转储 - cached_resource gem

使用 cached_resource gem 对活动资源进行缓存。 用户模型 class User < ActiveResource::Base cached_resource class teachers < SimpleDelegator attr_acc...

10得票1回答
符号垃圾回收 Ruby 2.2.1

自Ruby 2.2+版本开始,引入了符号的垃圾回收机制。我在irb中编写了以下代码片段: before = Symbol.all_symbols.size #=>3331 100_000.times do |i| "sym#{i}".to_sym end Symbol.all_...

10得票2回答
如何在Ruby中优化模块方法?

你可以使用以下方式优化你的类: module RefinedString refine String do def to_boolean(text) !!(text =~ /^(true|t|yes|y|1)$/i) end end end 但如何优化模块...