1
1

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.

Crystal - Top Level Namespace - macros - pp #crystal

Last updated at Posted at 2015-06-22

概要

Crystal の Top Level Namespace のマクロ、 pp について

pp とは

PrettyPrint。人間にとって見やすい形式で標準出力を行います。

:sparkles::gem::sparkles: Crystalの例

プログラム

ary = [1, 2, 3]
hash = { key1: :value1, key2: :value2 }
pp [
  1,
  "hoge",
  ary,
  ary + ary,
  hash,
  [ary, hash]
]

出力

[1, "hoge", ary, ary + ary, hash, [ary, hash]] = [1, "hoge", [1, 2, 3], [1, 2, 3, 1, 2, 3], {:key1 => :value1, :key2 => :value2}, [[1, 2, 3], {:key1 => :value1, :key2 => :value2}]]

:gem: Rubyの例

プログラム

require 'pp'

ary = [1, 2, 3]
hash = { key1: :value1, key2: :value2 }
pp [
  1,
  "hoge",
  ary,
  ary + ary,
  hash,
  [ary, hash]
]

出力

[1,
 "hoge",
 [1, 2, 3],
 [1, 2, 3, 1, 2, 3],
 {:key1=>:value1, :key2=>:value2},
 [[1, 2, 3], {:key1=>:value1, :key2=>:value2}]]

まとめ

Crystalのppは、出力前の式も標準出力してくれます。
しかし、出力が長くなった場合の改行はしてくれないようです。

外部資料

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?