打印出僵尸的名字和墓地.僵尸轨道 [英] Print out the zombie's name and graveyard. Rails for Zombies

查看:101
本文介绍了打印出僵尸的名字和墓地.僵尸轨道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何打印出僵尸的名字和墓地

How to print out the zombie's name and graveyard

您可以在不添加字符串的情况下将其串联吗?

Can you concatenate this without adding a string?

z = zombie.find(3)

puts z.name
puts z.graveyard

这是错误的吗?它只输出最后一个,墓地.

Is this wrong? It is only outputing the last one, graveyard.

推荐答案

您应该使用

puts "#{z.name} #{z.graveyard}"

您可能想知道如何评估它!您应该查看插值.表达式z.namez.graveyard的结果被串联/插入到字符串中. #{ }中的所有表达式都会被求值并插入到字符串中

You might be wondering how this would get evaluated! You should look at Interpolation. The result of the expressions z.name and z.graveyard gets concatenated/inserted into the string. Any expression that goes into #{ } gets evaluated and inserted into the string

这篇关于打印出僵尸的名字和墓地.僵尸轨道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆