在Ruby 1.9.2堆栈跟踪中,我经常看到给出的方法<top (required)>,如下面的堆栈部分所示.这是什么意思?我的Ruby安装是否巧妙地破坏了?
Could not find abstract-1.0.0 in any of the sources
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/spec_set.rb:87:in `block in materialize'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/spec_set.rb:81:in `map!'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/spec_set.rb:81:in `materialize'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/definition.rb:90:in `specs'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/definition.rb:135:in `specs_for'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/definition.rb:124:in `requested_specs'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/environment.rb:23:in `requested_specs'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/runtime.rb:11:in `setup'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler.rb:107:in `setup'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/setup.rb:14:in `<top (required)>'
<internal:lib/rubygems/custom_require>:33:in `require'
<internal:lib/rubygems/custom_require>:33:in `rescue in require'
<internal:lib/rubygems/custom_require>:29:in `require'
Run Code Online (Sandbox Code Playgroud) 一位同事需要在Rails应用程序中对一组ActiveRecord对象进行排序.他尝试了显而易见的Array.sort!但看起来非常缓慢,需要32秒才能获得3700个物体.所以以防万一它是速度变慢这些大发物,他通过排序小对象的数组,然后重新排序ActiveRecord对象的原始数组匹配重新实现排序-如下面的代码.田田!排序现在需要700毫秒.
这真让我感到惊讶.Ruby的排序方法最终会复制关于该位置的对象而不仅仅是引用吗?他正在使用Ruby 1.8.6/7.
def self.sort_events(events)
event_sorters = Array.new(events.length) {|i| EventSorter.new(i, events[i])}
event_sorters.sort!
event_sorters.collect {|es| events[es.index]}
end
private
# Class used by sort_events
class EventSorter
attr_reader :sqn
attr_reader :time
attr_reader :index
def initialize(index, event)
@index = index
@sqn = event.sqn
@time = event.time
end
def <=>(b)
@time != b.time ? @time <=> b.time : @sqn <=> b.sqn
end
end
Run Code Online (Sandbox Code Playgroud) 在Postgres 9.3数据库中,我有一个表,其中一列包含JSON,如下面示例中显示的测试表中所示.
test=# create table things (id serial PRIMARY KEY, details json, other_field text);
CREATE TABLE
test=# \d things
Table "public.things"
Column | Type | Modifiers
-------------+---------+-----------------------------------------------------
id | integer | not null default nextval('things_id_seq'::regclass)
details | json |
other_field | text |
Indexes:
"things_pkey" PRIMARY KEY, btree (id)
test=# insert into things (details, other_field)
values ('[{"json1": 123, "json2": 456},{"json1": 124, "json2": 457}]', 'nonsense');
INSERT 0 1
test=# insert into things (details, other_field)
values ('[{"json1": 234, "json2": 567}]', 'piffle');
INSERT …Run Code Online (Sandbox Code Playgroud) 我正在开发一个Bash脚本,它被设计为"作为工具"运行,因此名称没有扩展名,#!/usr/bin/bash顶部有一行.
我的脚本有很多功能,所以如果我可以使用Vim的标记支持跳转代码会很好,但是我无法使用ctags来标记文件.ctags mytool生成一个空白的标签文件,除了顶部的评论部分.
如果我将我的文件重命名为mytool.sh,则ctags mytool.sh效果很好.
有没有办法强制ctags标记没有扩展名的文件?我尝试过在ctags手册中找到的一些选项,这些选项似乎与文件扩展名有关,但没有快乐.
我想以这样的方式链接到一行代码,即使文件在将来的提交中更新,该链接也将继续工作。
在 Github 中,我会通过按“y”移动到包含 blob SHA 的页面版本来执行此操作:
https://github.com/rails/rails/blob/b49e38b76b0998b0a8312d8c08c98728d3de2006/activerecord/lib/arel/attributes/attribute.rb#L30
(或者,GitHub 在“...”菜单中有一个“复制永久链接”选项,当您选择一行时,该菜单会出现在页边空白处 -记录在此处。)
Azure DevOps 中是否有等价物?
我选择一行时得到的链接具有以下形式:
https://.../_git/project?path=XXXX&version=GBmaster&line=426&lineStyle=plain&lineEnd=427&lineStartColumn=1&lineEndColumn=1
许多参数定义了选择,但没有固定文件版本。
ruby ×2
azure-devops ×1
bash ×1
ctags ×1
json ×1
performance ×1
postgresql ×1
sorting ×1
sql ×1
vim ×1