RubyにはObjectSpaceというモジュールがあって、Heap内のオブジェクトを見たりすることができます。デバッグ目的で使うものだと思いますが、過去にとあるライブラリの中で使われていてRubyがsegmentation faultで落ちたりして痛い目を見たことがあります。怖いやつです。 たとえばObjectSpace.count_objectsはHeap内のオブジェクトを種類ごとにカウントしてHashで返してくれます。 def diff_object GC.disable old = ObjectSpace.count_objects yield if block_given? ObjectSpace.count_objects.each do |k,v| before = old[k] || 0 diff = v - before puts "[#{k}] #{before} ->
Friday, October 27, 2017 Transactions in Ruby on Rails can be deceptively tricky to master. The following illustrates a few examples of when using simple transactions can go awry and inadvertently fail to provide atomicity. The Setup This article explores a simple app composed of surveys and questions. Surveys require a name. Questions require some text. For the examples surveys have and belong to
On a recent project, a client’s test suite had slowed down to a painful 15 minutes even when running with parallelization. It was great to see that the team maintained a balanced testing pyramid, but we were surprised by the completion times of even the simplest unit specs. # spec/models/user_spec.rb describe "associations" do subject(:user) { User.new } it { should have_many(:orders) } # 12 addit
“Prefer composition over inheritance” is a popular saying amongst programmers. In this article, I want to demonstrate what that looks like. We’re going to refactor some Rails classes from inheritance to composition. Then we’ll refactor again from composition to something even better: data. Inheritance (The Original Code) In an attempt to show “real” code, I’ve taken this example from the Rails cod
Reporting handled errors Reporting handled errors allows your application to recover from an error, while still reporting it to BugSnag. To notify Bugsnag of a handled exception you can call Bugsnag.notify: begin raise 'Something went wrong!' rescue => e Bugsnag.notify(e) end Sending custom diagnostics In order to quickly understand and fix some errors, it is often helpful to send additional diagn
Pry is a great tool for Ruby. You have probably used it by setting binding.pry in the middle of your code like so: From: lib/dry/types/hash/schema.rb @ line 58 Dry::Types::Hash::Schema#try: 40: def try(hash, &block) 41: success = true 42: output = {} 43: 44: begin 45: result = try_coerce(hash) do |key, member_result| 46: success &&= member_result.success? 47: output[key] = member_result.input 48:
はじめに この記事はByebug(バイバグ)というgemを使ったデバッグ方法を説明するチュートリアル記事です。 JavaやC#のようなコンパイル型の言語ではEclipseやVisual StudioのようなIDEを使って開発することが主流です。 なので、自然とIDEに標準装備されているデバッガを使ってステップ実行したりすることが多いと思います。 一方、RubyではRubyMineのような有料IDEもあるものの、IDEではなくテキストエディタを使って開発している人の方がまだまだ多いと思います。 そうすると、初心者の方はなんとなく「Rubyでデバッガを使ってデバッグするのは無理なのでは?」と考えてしまう人も多いかもしれません。(僕は初心者の頃そう思ってました・・・。) ですが、そんなことはありません! RubyでもIDEを使わずにターミナル上でデバッガを使ってデバッグすることは可能です。 とい
===================== /Users/richardschneeman/documents/projects/my_rails_app/app/controllers/projects_controller.rb:18:in `new' /Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action' /Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/abstract_controller/base.rb:183:in `process_action' /Users/
In our previous post, The Basics of MVC in Rails, we discussed theoretical aspects of the MVC design pattern. We defined what MVC stands for, identified what each MVC component is responsible for, addressed what happens when a component contains redundant logic, and, most importantly, we introduced the concept of refactoring. In this article, as promised, we’ll show you each design pattern at work
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く