binding.pry使い方

知らなかったこと:
処理を止めたコントローラーで、コンソールから変数を入力すると、定義されていれば値が帰ってくる。定義されていなければ、nilが帰ってくる。

viewでも実行できる

<%= @book.title %>
<% binding.pry %>

これで、@book.title内に本当に正しい情報が入っているか確かめることができる。

デバックを使って学習することができる

@books.methods

これを実行したら、使えるメソッドが大量に出てくる。

[4] pry(#<#<Class:0x000055eb1296c988>>)> @posts_get_likes.methods
=> [:per,
 :max_paginates_per,
 :total_pages,
 :padding,
 :current_page,
 :next_page,
 :out_of_range?,
 :current_per_page,
 :last_page?,
 :prev_page,
 :first_page?,
 :offset_value,
 :limit_value,
 :offset_value=,
 :limit_value=,
 :limit,
 :page,
 :total_count,
 :offset,
 :entry_name,
 :max_per_page,
 :paginates_per,
 :max_pages,
 :max_pages_per,
 :default_per_page,
 :to_json,
 :third,
 :fourth,
 :fifth,
 :forty_two,
 :third_to_last,

<page break> --- Press enter to continue ( q<enter> to break ) --- <page break>

 :second_to_last,
 :to_h,
 :including,
 :excluding,
 :without,
 :include?,
 :compact_blank!,
 :pretty_print,
 :at,
 :fetch,
 :last,
 :union,
 :difference,
 :push,
 :append,
 :pop,
 :shift,
 :unshift,
 :each_index,
 :join,
 :rotate,
 :rotate!,
 :sort!,
 :sort_by!,
 :collect!,
 :map!,
 :select!,
 :filter!,
 :keep_if,
 :values_at,
 :delete_at,

<page break> --- Press enter to continue ( q<enter> to break ) --- <page break>

 :delete_if,
 :reject!,
 :transpose,
 :fill,
 :assoc,
 :rassoc,
 :uniq!,
 :compact,
 :*,
 :+,
 :flatten!,
 :&,
 :shuffle,
 :sample,
 :compact!,
 :flatten,
 :combination,
 :shuffle!,
 :-,
 :repeated_permutation,
 :sort,
 :product,
 :bsearch,
 :repeated_combination,
 :count,
 :blank?,
 :find_index,
 :to_param,
 :select,
 :filter,
 :reject,
#以下省略

Dockerを使っている場合

docker attach コンテナ名