小编kru*_*hah的帖子

如何在ruby中对文件进行排序

这是我的文件内容.

Receivables=Por cobrar
Payables=Cuentos por pagar 
ytdPurchases.label=Purchases YTD
validationError.maxValue=Value is too large, maximum value allowed is {0}
Run Code Online (Sandbox Code Playgroud)

我想按字母顺序对这些内容进行排序......我怎么能这样做?

更新:此代码将对我的文件进行排序.

new_array = File.readlines("#{$base_properties}").sort
File.open("#{$base_properties}","w") do |file|
  new_array.each {|n| file.puts(n)}
end
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法来排序文件?

ruby sorting file

5
推荐指数
2
解决办法
5461
查看次数

如何用西班牙语加载我的rails控制台

我已经建立了一个西班牙语和英语的应用程序.在我的控制台上,如果对象返回验证错误,我将收到英文错误消息.我想设置我的rails控制台,所以我将获得西班牙语验证错误消息.

ruby ruby-on-rails

4
推荐指数
1
解决办法
3634
查看次数

优化Android应用程序

我想做我的Android应用程序的优化.

任何人都可以告诉你有什么不同的方法来优化Android中的代码和性能?

我经历了一个工具,即Zipalign:一个简单的优化.

可以使用其他任何工具吗?

谢谢.

testing optimization performance android

4
推荐指数
1
解决办法
7910
查看次数

迭代特定范围的哈希值

如何传递哈希范围以从索引1到最后一次迭代?

h = {}

h[1..-1].each_pair do |key,value|
  puts "#{key} = #{value}
end
Run Code Online (Sandbox Code Playgroud)

此代码返回错误.我怎么可以在哈希中传递范围?

编辑:

我想打印第一个键和值而不进行任何计算.

从第二个键和值我想在我的哈希值上做一些计算.

为此我写了这段代码... store_content_in_hash包含键和值.

first_key_value = store_content_in_hash.shift
f.puts first_key_value[1]
f.puts
store_content_in_hash.each_pair do |key,value|
  store_content_in_hash[key].sort.each {|v| f.puts v }
  f.puts
end
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法来解决这个问题?

ruby hash

4
推荐指数
1
解决办法
3480
查看次数

我可以使用github-services挂钩将我的订阅源发布到其他服务吗?

Github已经开发了github-services钩子来推送其他服务,比如bugzilla,campfire,basecamp ..

可以使用相同的github-services挂钩将我的应用程序数据推送到其他服务吗?如果是,我如何将github-services集成到我的Rails应用程序中.

任何帮助?有什么建议吗?

更新我可以在我的Rails应用程序中将github-services钩子源代码集成为Sinatra应用程序吗?如何从我的应用程序触发器中调用其他服务(bugzilla,campfire,basecam,twitter)钩子?

例如,当一个用户在其他用户的墙上发布消息时,应将消息发送到其他服务,如bugzilla,campfire,basecamp,twitter ......

ruby api ruby-on-rails github github-services

4
推荐指数
1
解决办法
966
查看次数

用Ubuntu安装JRuby 1.6.7 + Rails 3?

在Ubuntu上安装JRuby 1.6.7和Rails 3的博客或教程?

jruby jrubyonrails

4
推荐指数
1
解决办法
3089
查看次数

TypeError:错误的参数类型Class(预期模块)

在app/models/abc/xyz.rb中

module Abc::Xyz
  extend ActiveSupport::Concern
end
Run Code Online (Sandbox Code Playgroud)

在app/models/abc.rb里面

class Abc < ActiveRecord::Base
  include Abc::Xyz 
end
Run Code Online (Sandbox Code Playgroud)

当我尝试从Abc.where(id:id)获取数据时,它有时会起作用,有时会返回此错误(TypeError:错误的参数类型Class(预期的模块)).

TypeError: wrong argument type Class (expected Module)
      app/models/abc.rb:2:in `include'
      app/models/abc.rb:2:in `<class:Abc>'
      app/models/abc.rb:1:in `<top (required)>'
      activesupport (3.2.17) lib/active_support/dependencies.rb:469:in `load'
      activesupport (3.2.17) lib/active_support/dependencies.rb:469:in `block in load_file'
      activesupport (3.2.17) lib/active_support/dependencies.rb:639:in `new_constants_in'
      activesupport (3.2.17) lib/active_support/dependencies.rb:468:in `load_file'
      activesupport (3.2.17) lib/active_support/dependencies.rb:353:in `require_or_load'
      activesupport (3.2.17) lib/active_support/dependencies.rb:502:in `load_missing_constant'
      activesupport (3.2.17) lib/active_support/dependencies.rb:192:in `block in const_missing'
      activesupport (3.2.17) lib/active_support/dependencies.rb:190:in `each'
      activesupport (3.2.17) lib/active_support/dependencies.rb:190:in `const_missing'
      activesupport (3.2.17) lib/active_support/inflector/methods.rb:230:in `block in constantize'
      activesupport (3.2.17) lib/active_support/inflector/methods.rb:229:in `each'
      activesupport …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails activesupport-concern

4
推荐指数
2
解决办法
2万
查看次数

ruby脚本/ delayed_job启动的问题.Windows上的delayed_job和守护进程

得到这个错误.

  pid-file for killed process 8600 found (C:/cyncabc/tmp/pids/delayed_job.pid), deleting.
  c:/ruby/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/daemonize.rb:103:in `fork': fork() function is unimplemented on this machine (NotImplementedError)
        from 
  c:/ruby/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/daemonize.rb:103:in `safefork'
        from 
  c:/ruby/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/daemonize.rb:145:in `call_as_daemon'
        from 
  c:/ruby/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/application.rb:219:in `start_proc'
        from 
  c:/ruby/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/application.rb:255:in `start'
        from 
  c:/ruby/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/controller.rb:69:in `run'
        from 
  c:/ruby/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons.rb:188:in `run_proc'
        from c:/ruby/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/cmdline.rb:105:in `call'
        from c:/ruby/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/cmdline.rb:105:in `catch_exceptions'
        from c:/ruby/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons.rb:187:in `run_proc'
        from c:/ruby/lib/ruby/gems/1.8/gems/delayed_job-2.0.3/lib/delayed/command.rb:71:in `run_process'
        from c:/ruby/lib/ruby/gems/1.8/gems/delayed_job-2.0.3/lib/delayed/command.rb:65:in `daemonize'
        from c:/ruby/lib/ruby/gems/1.8/gems/delayed_job-2.0.3/lib/delayed/command.rb:63:in `times'
        from c:/ruby/lib/ruby/gems/1.8/gems/delayed_job-2.0.3/lib/delayed/command.rb:63:in `daemonize'
        from script/delayed_job:5
Run Code Online (Sandbox Code Playgroud)

有没有解决这个问题的解决方案?它与ruby脚本/ delayed_job运行正常.

ruby ruby-on-rails delayed-job

3
推荐指数
1
解决办法
2468
查看次数

在Ruby中编写此计算的最佳方法?

在Ruby中编写此计算的最佳方法是什么?

amt = self.alt_inv - (self.alt_tax ? self.alt_tax : 0)
    - (self.alt_freight ? self.alt_freight : 0)
    - (self.misc1_amt ? self.misc1_amt : 0)
    - (self.misc2_amt ? self.misc2_amt : 0)
Run Code Online (Sandbox Code Playgroud)

ruby

3
推荐指数
3
解决办法
199
查看次数

将多级数组转换为单级数组?

我想转换这个数组

[[["b", "c"], ["c", "d"]], [["v", "e"], ["r", "g"]]]
Run Code Online (Sandbox Code Playgroud)

[["b", "c"], ["c", "d"], ["v", "e"], ["r", "g"]]
Run Code Online (Sandbox Code Playgroud)

我该怎么转换呢?

ruby

3
推荐指数
1
解决办法
78
查看次数