26
25

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.

見やすいprint

Posted at

Rubyのirbとかpryとかでオブジェクトの操作をやってみるとき、うろ覚えのメソッドを調べるためにいちいちリファレンスマニュアルを見なくてもオブジェクトに直接聞くことができます。

hash = Hash.new
puts hash.methods
rehash
to_hash
to_a
inspect
 :

これだとイマイチわかり辛いのですが、オブジェクトの表示を分かりやすくしてくれるモジュールawesome_printを使うと感激の見やすさになります。

require 'awesome_print'
ap hash.methods
[
    [  0]                          !()                 Hash (BasicObject)
    [  1]                         !=(arg1)             Hash (BasicObject)
    [  2]                         !~(arg1)             Hash (Kernel)
    [  3]                        <=>(arg1)             Hash (Kernel)
    [  4]                         ==(arg1)             Hash
    [  5]                        ===(arg1)             Hash (Kernel)
 :

並び順もステキな上に、どこで定義されているメソッドかまで一目瞭然ヽ(´ー`)ノ
実際にコンソールで実行すると色も付いていて惚れます。

26
25
5

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
26
25

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?