LoginSignup
0
1

More than 5 years have passed since last update.

ERB内で多重読み込みしてネストされたリストを出力する

Last updated at Posted at 2016-12-28

何をするの?

ERB 内で多重読み込みしてネストされたリストを出力してみます。

Fun
  Sport
    Surfing
    Extreme knitting
  Friends
Work
  Reports
    Annual
    Status
  Trips

コード

require 'erb'

MY_CATEGORIES = <<SPEC
Fun
<%= ERB.new(FUN, nil, '-', 'funs').result(binding) -%>
Work
<%= ERB.new(WORK, nil, '-', 'works').result(binding) -%>
SPEC

FUN = <<SPEC
  Sport
<%= ERB.new(SPORT, nil, '-', 'sports').result(binding) -%>
  Friends
SPEC

SPORT = <<SPEC
    Surfing
    Extreme knitting
SPEC

WORK = <<SPEC
  Reports
<%= ERB.new(REPORT, nil, '-', 'reports').result(binding) -%>
  Trips
SPEC

REPORT = <<SPEC
    Annual
    Status
SPEC

puts ERB.new(MY_CATEGORIES, nil, '-').result(binding)

# Fun
#   Sport
#     Surfing
#     Extreme knitting
#   Friends
# Work
#   Reports
#     Annual
#     Status
#   Trips

まとめ的なもの

eoutvar の指定が必要でした。

0
1
0

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