RClass 的代码我也读过一部分,还没完全读完读懂。我想把我的问题表达的更具体一些,便于讨论。
class B
end
b1 = B.new
b1.instance_eval{
@a = 1
@b = 2
}
b2 = B.new
b2.instance_eval{
@c = 1
@d = 2
}
同一个类不同对象的实例变量千差万别,key 也皆不同。
我有个疑问:如果对象的实例变量在 Robject 中是个数组,它的 key 在哪呢?
Ruby 的对象是一堆的实例变量,加上指向类的引用。假如你自己在 Ruby 中定义了一个类,那么这个类的对象在 C 中是通过 Robject Structure 来实现。
As you can see, each klass value points to the Mathematician RClass struc- ture, and each RObject structure has a separate array of instance variables. Both arrays contain VALUE pointers—the same pointer that Ruby uses to refer to the RObject structure. (Notice that one of the objects contains two instance variables, while the other contains only one.)
为了性能,一些简单的 value,比如 1, 2, 3, 4, 5
,虽然是对象,但 Ruby 不使用任何 structure 来实现。
As a performance optimization, Ruby saves small integers, symbols, and a few other simple values with- out any structure at all, placing them right inside the VALUE pointer, as shown in Figure 5-5.
推荐两位阅读《Ruby under a microscope》
cool!
这个错误我从没有碰到过。在终端中执行 rvm requirements
会列出一堆的依赖,都安装了吗?
下次记得给代码排版,语法:
```bash
```
开发速度好快
收到客户端请求后,去访问一些远端服务,得到数据,写数据库。
很有可能 external request 把你的 web server 的进程 block 住了。
你换成 puma 会好一些。(最多阻塞一个线程,而不是一个进程)
整个重构过程写的很详细,但缺少了两个重要信息:
建议楼主补齐,否则其他人无法做更加深入的探讨。
这是我的版本,供参考:
FactoryGirl.define do
# user
factory :user do
# 动态 name,可创建多个用户
name { SecureRand.hex }
end
end
FactoryGirl.define do
factory :post do
user { create :user }
title "Title"
content "Content"
trait :with_comments do
ignore do
number_of_comments 3
end
after :create do |post, evaluator|
FactoryGirl.create_list :comment, evaluator.number_of_comments, :post => post
post.reload
end
end
end
end
创建 user1: user1 = create :user
创建 user2: user2 = create :user
创建一个 post: post = create :post
创建一个含有 3 个 comments 的 post: post = create :post, :with_comments, :number_of_comments => 3
def setup
@post = create :post, :with_comments, :number_of_comments => 3
@comment = @post.comments.last
end
freeze
方法冻结了变量名背后代表的对象(object),而不是变量名(variable identifier)本身。
这样理解的对吗?
标题有错别字啊
[上海] 雅克菲招聘 Rubyy 高级工程师一名 (Ruby 高级工程师一枚)
上传个头像吧
升级后,我的 zsh 和 oh my zsh 没任何问题
看来楼主没参加今年的 ruby conf,哈哈。
Newrelic 有免费版,仅保存一周的数据,不过够你用的了。
every 2.hours do
runner "MyModel.some_process"
rake "my:rake:task"
command "/usr/bin/my_great_command"
end
装一个 Newrelic,每一步耗费的时间一清二楚。
再弄两张表
book_tags
tags
这样更符合范式
https://github.com/mbostock/d3/wiki/Gallery
D3.js 这个库展示数据相当不错。
bundle exec 只是负责加载 Gemfile.lock 中的 gem,把他们加到 $LOAD_PATH 中,然后 require.
你最好把 cron job 放到单独的机器上去执行。
你该买机器了。。。
国内:以前用过 美洽 ,支持 Html5、Native SDK 等多重接入方式,也还不错。
国外:推荐 uservoice。
外部请求没有加超时是导致 sidekiq frozen 的最常见原因
https://github.com/mperham/sidekiq/wiki/Problems-and-Troubleshooting#user-content-frozen-processes
解决方法如下
测试自动赞 :plus1:
我们以前是这样干的:
可以缓存,但是不建议这么干。
但是数据量大时(比如几千个 Cate 的数据),一堆 ActiveRedocrd 对象的 序列化/反序列化 非常的耗时,不划算。
自己做个测试试试。