23
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RubyAdvent Calendar 2012

Day 4

pry/irbの`_`

Last updated at Posted at 2012-12-26

pryやirbで何か処理を実行したとき,結果を変数に代入し忘れたときに使う.以下pryでの実行例

[1] pry(main) > User.find_by_url_name('yaotti') # 本当はuser = User.find_by... としたかった
=> #<User id: 1, url_name: "yaotti", ...>
[2] pry(main) > user = _
=> #<User id: 1, url_name: "yaotti", ...>

Special Locals · pry/pry Wikiを読めば他の特殊変数も全部載ってるけど,_が一番便利.

その他pry関連でおすすめ記事

pryの基本: ググるよりもまずはpry
awesome_print を pry の表示のデフォルトに使う
pryを使った快適なRubyライブラリのコードリーディング&開発方法 #開発環境(未だにストッックされ続けている記事.pryのedit-methodは本当に便利)

23
23
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?