小编Phr*_*ogz的帖子

使用simple_form自定义错误消息

我正在使用simple_form gem.我想自定义用户验证失败时显示的错误消息.我怎么能做到这一点?

ruby validation error-handling ruby-on-rails ruby-on-rails-3

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

Bundler通过RVM提供什么?

我不确定这两个工具之间的区别.似乎有很大的重叠,但我一直在使用RVM并面临一些错误兼容性问题.

Bundler做什么RVM没有?

ruby bundler rvm ruby-on-rails-3

7
推荐指数
1
解决办法
763
查看次数

什么相当于Haskell中Ruby的pnormaldist统计函数?

如下所示:http://www.evanmiller.org/how-not-to-sort-by-average-rating.html

这是Ruby代码本身,在Statistics2库中实现:

# inverse of normal distribution ([2])
# Pr( (-\infty, x] ) = qn -> x
def pnormaldist(qn)
  b = [1.570796288, 0.03706987906, -0.8364353589e-3,
       -0.2250947176e-3, 0.6841218299e-5, 0.5824238515e-5,
       -0.104527497e-5, 0.8360937017e-7, -0.3231081277e-8,
       0.3657763036e-10, 0.6936233982e-12]

  if(qn < 0.0 || 1.0 < qn)
    $stderr.printf("Error : qn <= 0 or qn >= 1  in pnorm()!\n")
    return 0.0;
  end
  qn == 0.5 and return 0.0

  w1 = qn
  qn > 0.5 and w1 = 1.0 - w1
  w3 = -Math.log(4.0 * …
Run Code Online (Sandbox Code Playgroud)

ruby statistics haskell hackage

7
推荐指数
2
解决办法
1661
查看次数

用于"if(范围内的数字)然后......"的Ruby快捷方式

以下是否有Ruby快捷方式?

if (x > 2) and (x < 10)
  do_something_here
end
Run Code Online (Sandbox Code Playgroud)

我以为我看到了那种效果,但无法找到它的参考.当然,当你不知道你正在寻找什么算子时,很难查找.

ruby ruby-on-rails

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

找到圆上的点的度数(0-360º)

我正在开发一个小型的webapp,我需要在其中旋转形状.我想通过抓住圆上的一个点然后拖动它来旋转图像来实现这一点.

这是一个快速说明,以帮助解释事情:

圈子上的两个点,我想找到p1的度数

我的主圆可以在画布上的任何位置拖动.我知道它的半径(r)和12点(p0)总是(cx,cy - r).我需要知道的是p1的度数(0-360º)所以我可以用Raphael.rotate()相应地旋转主圆的内容.

我已经通过一系列不同的JavaScript配方来找到这个(示例),但似乎没有一个给我0-360之间的值,而我的基本数学技能都非常不足.

颜色选择器演示(滑动沿右边的环光标)有我想要的行为,但即使钻研的源代码后,我似乎无法准确地复制它.

任何指向我正确方向的东西将不胜感激.

svg trigonometry raphael

7
推荐指数
1
解决办法
2666
查看次数

从数组中的对象中删除实例变量

我是Ruby的新手,我只是在玩想法,我想要做的是从我创建的country_array中删除@continent数据.完成了大量的搜索,可以找到有关完整删除元素的相关信息,但无法找到如何专门删除@continent数据.请保持任何答案相当简单,因为我是新的,但任何帮助非常感谢.

class World
  include Enumerable
  include Comparable

  attr_accessor :continent
  def <=> (sorted)
    @length = other.continent
  end

  def initialize(country, continent)
    @country = country
    @continent = continent
  end 
end

a = World.new("Spain", "Europe")
b = World.new("India", "Asia")
c = World.new("Argentina", "South America")
d = World.new("Japan", "Asia")

country_array = [a, b, c, d]

puts country_array.inspect

[#<World:0x100169148 @continent="Europe", @country="Spain">, 
#<World:0x1001690d0 @continent="Asia", @country="India">, 
#<World:0x100169058 @continent="South America", @country="Argentina">, 
#<World:0x100168fe0 @continent="Asia", @country="Japan">]
Run Code Online (Sandbox Code Playgroud)

ruby

7
推荐指数
1
解决办法
9212
查看次数

匹配字符串中连续字符的序列

我有字符串,"111221"并希望匹配所有连续的相等整数集:["111", "22", "1"].

我知道有一个特殊的正则表达式可以做到这一点,但我不记得了,我在Googling很糟糕.

ruby regex

7
推荐指数
1
解决办法
2955
查看次数

在Ruby中绘制点和矩形

我正在寻找一种简单的方法来绘制10点和矩形,以便能够看到我的算法出错的地方.我看了看gnuplot,但看起来特别糟糕的是绘制矩形.

ruby plot svg

7
推荐指数
2
解决办法
2583
查看次数

无法加载此类文件 - ruby​​-wmi(LoadError)&无法加载此类文件 - win32/service(LoadError)

我确实安装了下面提到的红宝石东西

在此输入图像描述

当我尝试执行chef-client时,我收到下面提到的错误

c:\RubyDevKit>chef-client
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- ruby-wmi (LoadError)
        from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/chef-10.14.4/lib/chef/provider/env/windows.rb:20:in `<top (required)>'
        from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/chef-10.14.4/lib/chef/providers.rb:49:in `<top (required)>'
        from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/chef-10.14.4/lib/chef.rb:25:in `<top (required)>'
        from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/chef-10.14.4/bin/chef-client:23:in `<top (required)>'
        from C:/Ruby193/bin/chef-client:23:in `load'
        from C:/Ruby193/bin/chef-client:23:in `<main>'
Run Code Online (Sandbox Code Playgroud)

Ruby193文件夹结构(缺失)

在此输入图像描述

ruby windows rubygems chef-infra

7
推荐指数
2
解决办法
7337
查看次数

使用P4Merge合并XML

我(大型)公司使用Perforce进行大部分源控制.(我无法逃避这一点.)

同事和我经常不得不同时处理同一个基于XML的文件.当合并我们的变化时,P4Merge通常不像我想的那么聪明.例如,考虑这个超级简单的XML文件和两个碰撞的变体:

简单的XML文件和两个具有相同结束标记的变体在同一个地方.

如图所示,P4Merge不支持XML,并且只保留一个公共副本</b>.

如何修改Perforce工具本身以支持更智能的XML合并,或者如何修改Perforce工具链以使用更智能的合并工具作为Resolve流程的一部分?

xml merge perforce

7
推荐指数
1
解决办法
1516
查看次数