LoginSignup
4
4

More than 5 years have passed since last update.

シンボルの配列の%記法をバリバリ使っていくことにした

Last updated at Posted at 2015-01-26

Ruby 2.0 で追加されたシンボルの配列を表す%記法のリテラルがあります。

%i(foo bar)  # => [:foo, :bar]
  • %i!STRING!
    要素がシンボルの配列(空白区切り)
  • %I!STRING!
    要素がシンボルの配列(空白区切り)。式展開、バックスラッシュ記法が有効

Rails なんかではシンボルの配列をバリバリ使うにも関わらず、あんまり使用例を見ません。ただ、もう 2.0 以降だけを考えてればよい頃合いだろうし、バリバリ使っていきたいと思います。

before_action :require_login, except: %i(index show)

すっきり!

4
4
1

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