首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ruby here-带循环的doc

ruby here-带循环的doc
EN

Stack Overflow用户
提问于 2010-11-28 06:36:51
回答 1查看 1.7K关注 0票数 3

你能做一个循环和here-doc,像这样:

代码语言:javascript
复制
array.each do |ele|
  a=<<-TEXT
   ele
   some stuff
  TEXT
end

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-11-28 06:49:41

代码语言:javascript
复制
array = %w[one two many]

array.each do |ele|
  a=<<-TEXT
  This is some text and
  this --> #{ele} <-- is the ele!

  TEXT

  puts a
end

结果:

代码语言:javascript
复制
This is some text and
this --> one <-- is the ele!

This is some text and
this --> two <-- is the ele!

This is some text and
this --> many <-- is the ele!
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4294289

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档