Questions tagged «ruby»

Ruby是由松本行弘(Matz)于1995年创建的一种多平台开放源代码,动态的,面向对象的解释性语言。[ruby]标记用于与Ruby语言有关的问题,包括其语法和库。Ruby on Rails问题应标记为[ruby-on-rails]。



18
您提供的授权机制不受支持。请使用AWS4-HMAC-SHA256
AWS::S3::Errors::InvalidRequest The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.尝试将文件上传到新法兰克福地区的S3存储桶时出现错误。所有US Standard区域都可以正常使用。 脚本: backup_file = '/media/db-backup_for_dev/2014-10-23_02-00-07/slave_dump.sql.gz' s3 = AWS::S3.new( access_key_id: AMAZONS3['access_key_id'], secret_access_key: AMAZONS3['secret_access_key'] ) s3_bucket = s3.buckets['test-frankfurt'] # Folder and file name s3_name = "database-backups-last20days/#{File.basename(File.dirname(backup_file))}_#{File.basename(backup_file)}" file_obj = s3_bucket.objects[s3_name] file_obj.write(file: backup_file) AWS SDK(1.56.0) 如何解决? 谢谢。


1
为什么sum比inject(:+)快得多?
所以我在Ruby 2.4.0中运行一些基准测试,并意识到 (1...1000000000000000000000000000000).sum 立即计算,而 (1...1000000000000000000000000000000).inject(:+) 花了这么长时间,我才中止了手术。我的印象是这Range#sum是一个别名,Range#inject(:+)但似乎并非如此。那么sum,它是如何工作的,为什么比它那么快inject(:+)呢? 注意:的文档Enumerable#sum(由实现Range)没有说明任何有关延迟评估的内容或类似内容。
129 ruby 

2
红宝石发送方法传递多个参数
尝试通过以下方式动态创建对象和调用方法 Object.const_get(class_name).new.send(method_name,parameters_array) 哪个工作正常 Object.const_get(RandomClass).new.send(i_take_arguments,[10.0]) 但是将错误的参数数量1换为2 Object.const_get(RandomClass).new.send(i_take_multiple_arguments,[25.0,26.0]) 定义的随机类是 class RandomClass def i_am_method_one puts "I am method 1" end def i_take_arguments(a) puts "the argument passed is #{a}" end def i_take_multiple_arguments(b,c) puts "the arguments passed are #{b} and #{c}" end end 有人可以帮助我如何将多个参数动态发送到ruby方法吗
129 ruby 

8
命令rbenv install丢失
在Ubuntu 10.04我刚刚安装rbenv。安装命令不存在。 rbenv 0.4.0-49-g8b04303 Usage: rbenv <command> [<args>] Some useful rbenv commands are: commands List all available rbenv commands local Set or show the local application-specific Ruby version global Set or show the global Ruby version shell Set or show the shell-specific Ruby version rehash Rehash rbenv shims (run this …

6
xxx的副本已从模块树中删除,但仍处于活动状态
我很确定该错误与TenantIdLoader模块的实际内容无关。相反,它与ActiveSupport依赖关系有关。 我似乎无法摆脱这个错误。从我读到的内容来看,这是因为要么ActiveRecord::Base正在重新Company::TenantIdLoader加载,要么正在重新加载,并且某种程度上没有进行通信。请帮助!我真的很希望能够升级到Rails 4.2。 编辑 现在,我了解到这是因为我正在引用Tenant正在自动重新加载的内容。我需要能够实际引用该类,所以有人知道如何解决这个问题吗? config / application.rb config.autoload_paths += %W( #{config.root}/lib/company ) config / initializers / company.rb ActionMailer::Base.send(:include, Company::TenantIdLoader) lib / company / tenant_id_loader.rb module Company module TenantIdLoader extend ActiveSupport::Concern included do cattr_accessor :tenant_dependency self.tenant_dependency = {} after_initialize do self.tenant_id = Tenant.active.id if self.class.tenant_dependent? and self.new_record? and Tenant.active.present? and …


13
Ubuntu Rails在zlib上安装失败
我刚刚将开发箱移至Ubuntu 8.10。这是我第一次认真尝试Linux作为日常使用的操作系统,而我很难让Rails正常运行。我遵循了许多似乎都可以正常工作的教程,但是当我尝试对任何东西使用gem install或gem update时,出现如下错误: /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- zlib (LoadError) from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:1 from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/commands/update_command.rb:5 from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:167:in `load_and_instantiate' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:88:in `[]' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:144:in `find_command' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:131:in `process_args' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:102:in `run' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/gem_runner.rb:58:in …




6
Ruby在JavaScript中|| =(或等于)?
我喜欢Ruby的||=机制。如果变量不存在或为nil,则创建它并将其设置为等于: amount # is nil amount ||= 0 # is 0 amount ||= 5 # is 0 我现在需要在JavaScript中执行类似的操作。有什么惯例或正确的方式来做到这一点?我知道这||=是无效的语法。有两种明显的处理方法: window.myLib = window.myLib || {}; // or if (!window.myLib) window.myLib = {};
128 javascript  ruby  syntax 


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.