All right in the previous module we played around with the puts method in the B or interactive Ruby 好的，在上一个模块中，我们在 B 或交互式 Ruby 中使用了 puts 方法
program within our terminal or a command prompt. 我们的终端或命令提示符中的程序。
And now I want to play around with it within a regular doc. 现在我想在常规文档中使用它。
RB ruby file within our Atam text editor. 我们的 Atam 文本编辑器中的 RB rub​​y​​ 文件。
Let's begin by using the puts method twice to output two different strings. 让我们首先使用两次 puts 方法来输出两个不同的字符串。
I'll begin with puts. 我将从看跌期权开始。
Hello world. 你好世界。
And I'm going to place this within double quotes that ensures that this is going to be interpreted as 我将把它放在双引号内，以确保这将被解释为
a string. 一个字符串。
And remember a string in Ruby is just a collection of characters that are strung together or sequenced 请记住，Ruby 中的字符串只是串在一起或按顺序排列的字符集合
together. 一起。
So I'm going to do. 所以我要做。
Puts Hello world. 把你好世界。
And then the line below I'm going to write puts I'm alive and well with let's say an exclamation point. 然后我要写的下面这行我还活着并且很好，让我们说一个感叹号。
Now puts as we know simply outputs whatever you give it at the end to the screen. 正如我们所知，现在 puts 只是将你在末尾提供的任何内容输出到屏幕。
So when I execute and mutter we can see that hello world and I'm alive and well are going to appear 所以当我执行并咕哝时，我们可以看到 hello world 和 I'm alive and well 将会出现
here on the right. 在右边。
Everything that's within the double quotes will appear right here when it's printed. 双引号内的所有内容在打印时都会出现在此处。
You can also notice that each line here is on a separate line. 您还可以注意到这里的每一行都在单独的一行上。
So there's been an automatic line break created. 所以已经创建了一个自动换行符。
And that's actually a feature that's part of the puts method in Ruby. 这实际上是 Ruby 中 puts 方法的一部分的功能。
Whenever you use puts no matter what you write after it Ruby is automatically going to add a line break 每当你使用 puts 时，无论你在它后面写什么，Ruby 都会自动添加一个换行符
at the very end. 在最后。
So Astier Ruby has done outputting hello world it's going to add a line break which allows the next 所以 Astier Ruby 已经完成输出 hello world 它将添加一个换行符允许下一个
put statement which is I'm alive and well to begin on the very next line. 把我还活着并且很好的声明放在下一行开始。
In fact because I'm alive and well is also part of the puts method. 事实上，因为我还活着，所以也是 puts 方法的一部分。
Ruby will add a line break at the very end. Ruby 会在最后添加一个换行符。
Well here is just a little bit less visible or a little bit more difficult to see because of the whitespace 好吧，由于空白，这里的可见度稍微低一点或更难看到一点
right here. 就在这儿。
But rest assured each puts command is going to add a line break to the end. 但请放心，每个 puts 命令都会在末尾添加一个换行符。
Now it puts method is an example of a statement and a statement is a single command in Ruby. 现在它 puts 方法是一个语句的示例，而语句是 Ruby 中的单个命令。
So what we have here on line 1 is one statement and what we have here on line 2 is another statement 所以我们在第 1 行的是一个声明，而我们在第 2 行的是另一个声明
simply a command. 只是一个命令。
Now a statement can conclude with a semi-colon. 现在一个语句可以用分号结束。
That's a very popular design in many programming languages so you can see code like this. 这是许多编程语言中非常流行的设计，因此您可以看到这样的代码。
And this is valid Ruby. 这是有效的 Ruby。
However most Rubeus do not write the semicolon at the end of a single statement. 然而，大多数 Rubeus 不会在单个语句的末尾写分号。
The one exception where you may see this it's still uncommon is whenever you have more than one statement 您可能会看到这种情况的一个例外情况仍然不常见，那就是当您有多个语句时
per line. 每行。
In this case we have each statement on a separate line to help with readability but something like this 在这种情况下，我们将每条语句放在单独的行中以帮助提高可读性，但像这样
where you have multiple put statements on a single line is allowed. 允许在一行中有多个 put 语句。
And because we're separating each of them we have to use the semi-colon. 因为我们要将它们分开，所以我们必须使用分号。
You can think of the semi-colon as a terminator. 您可以将分号视为终止符。
It basically tells Ruby that whatever command it's processing that's the end. 它基本上告诉 Ruby，它正在处理的任何命令都是结束的。
That's the end of the line. 这是该行的结尾。
The end of the road. 路的尽头。
So in Ruby as reading. 所以在Ruby中作为阅读。
Puts Hello world. 把你好世界。
It knows that the semi-colon concludes that command and it can move on to the next one. 它知道分号结束了该命令，它可以继续执行下一个命令。
But you can see things are already getting kind of messy here. 但是你可以看到这里的事情已经变得有点混乱了。
So the general best practice is to write a single statement on a single line and because that's the 所以一般的最佳做法是在一行上写一条语句，因为那是
case in Ruby automatically knows to conclude a statement at the end of each line it doesn't need the Ruby 中的 case 自动知道在每一行的末尾结束一个语句，它不需要
semicolon. 分号。
The most common practice is to exclude the semicolon and simply write one statement per line. 最常见的做法是排除分号并简单地每行写一个语句。
So just like this as clean as it can possibly be is the most popular way to do it. 所以就像这样尽可能干净是最流行的方法。
So as we've seen so far the puts method output something to the screen and automatically adds a line 因此，正如我们到目前为止所看到的，puts 方法会向屏幕输出一些内容并自动添加一行
break to the end of the output. break 到输出结束。
So far we've done simple basic strings that just include common letters but remember that a string is 到目前为止，我们已经完成了仅包含常见字母的简单基本字符串，但请记住，字符串是
just a sequence of characters even in the ones above we have things like the exclamation point and the 只是一系列字符，即使在上面的字符中我们也有感叹号和
spaces. 空间。
These are not valid letters but these are valid characters and the strings include other characters 这些不是有效字母，但这些是有效字符，并且字符串包含其他字符
such as symbols. 比如符号。
So for example I can write something like. 因此，例如我可以写类似的东西。
Puts. 看跌期权。
I bought 5 dollars at the store that includes a number 5 in there and when I execute this we can see 我在商店买了 5 美元，里面有一个数字 5，当我执行这个时我们可以看到
that it's going to appear here to the right no problem. 它会出现在右边没问题。
And for something a bit more complex I can write. 对于更复杂的东西，我可以写。
Puts. 看跌期权。
I made 65 I can type. 我做了 65 我可以打字。
I made $65 for a profit of 25 percent. 我以 25% 的利润赚了 65 美元。
Exclamation point. 感叹号。
So in this one we use an exclamation point. 所以在这个中我们使用感叹号。
We use a percentage sign and a dollar sign in front of 65. 我们在 65 前面使用百分号和美元符号。
No problem. 没问题。
Ruby will simply output that string to the screen so the string can include more than just letters. Ruby 将简单地将该字符串输出到屏幕，因此该字符串可以包含的不仅仅是字母。
It can include spaces characters numbers and so on. 它可以包括空格字符数字等。
So the previous four examples have used the puts method to output a string which is just a collection 所以前面四个例子都是用puts方法输出了一个字符串，只是一个集合
of characters. 字符。
However we're not limited strictly to strings. 然而，我们并不仅限于字符串。
The puts method is a lot more versatile how. puts 方法更加通用。
So let's see what happens when we use puts with a simple number. 那么让我们看看当我们使用带有简单数字的 puts 时会发生什么。
I'm going to write puts 5 and you'll notice that 5 is not going to be wrapped in double quotes. 我要写 puts 5，你会注意到 5 不会用双引号引起来。
It's just the number 5. 这只是数字 5。
When I execute this code we can see that 5 appears here and no problem. 当我执行这段代码时，我们可以看到 5 出现在这里，没有问题。
And that's an integer number we can try a similar experiment with a floating point number. 这是一个整数，我们可以用浮点数进行类似的实验。
A floating point number just a number with a decimal component. 浮点数只是一个带有小数部分的数字。
So if I do something like puts three point 1 4 1 5 9 that's pi has an example of one floating point 因此，如果我做类似 puts three point 1 4 1 5 9 这样的事情，pi 有一个浮点数的例子
number. 数字。
Here we can see it outputs to the right. 在这里我们可以看到它向右输出。
No problem there. 没问题。
Now keep in mind that strings are not numbers strings are totally different. 现在请记住，字符串不是数字，字符串是完全不同的。
And sometimes it can be a little bit confusing. 有时可能会有点混乱。
For example if I write puts three point 1 4 1 5 9 but I wrap it in quotes it automatically becomes a 例如，如果我写 puts three point 1 4 1 5 9 但我用引号括起来它会自动变成
string. 细绳。
And when I execute this again we can see that on the right in the output there is no difference in how 当我再次执行此操作时，我们可以看到在输出的右侧，方式没有区别
it appears when used with puts. 它在与 puts 一起使用时出现。
However it's three point 1 4 1 5 9 within quotes is a string. 但是引号内的三点 1 4 1 5 9 是一个字符串。
It's a totally separate object and has totally separate functionalities. 它是一个完全独立的对象，具有完全独立的功能。
So it's something like numbers. 所以它有点像数字。
For example we can do mathematical operations with strings we cannot. 例如，我们可以用我们做不到的字符串进行数学运算。
And if you're using the wrong data type you can run into errors. 如果您使用了错误的数据类型，您可能会遇到错误。
So let me give you one example. 因此，让我举一个例子。
So what I'm going to do here is just remove the double quotes right here. 所以我在这里要做的就是删除这里的双引号。
And let's say below I want to do some kind of mathematical operation let's say I want to puts four plus 让我们在下面说我想做一些数学运算比方说我想把四加
three. 三。
Now in this case we have two numbers four and three. 现在在这种情况下，我们有两个数字 4 和 3。
And we use the plus sign which is a common programming operator or a sign or symbol for addition. 我们使用加号，它是一种常见的编程运算符或加法的符号或符号。
Much like it is in regular mathematics. 就像在常规数学中一样。
And we'll dive into this in greater detail in a few lessons. 我们将在几节课中更详细地探讨这一点。
For now we're simply adding four plus three and we can see here when we execute this. 现在我们只是简单地将四加三相加，当我们执行它时我们可以看到这里。
That ruby is successfully going to output 7 on the right. 右边那个ruby成功去输出7了。
It knows that when you have two numbers it can add them together to get the result. 它知道当你有两个数字时，它可以将它们加在一起得到结果。
And that's what we're putting are outputting on the right here. 这就是我们正在输出的内容。
However if one of our numbers so to speak is a string. 但是，如果我们的数字之一可以说是一个字符串。
If I do something like puts four plus three you can see I have wrapped that four in double quotes. 如果我做类似 put 4 plus 3 的操作，您会看到我已经用双引号将这 4 括起来。
It's no longer a a number. 它不再是一个数字。
It's now a string. 它现在是一个字符串。
So when Ruby looks at this it's going to think that it's a string it's just a random characters no different 因此，当 Ruby 看到它时，它会认为它是一个字符串，它只是一个随机字符，没有什么不同
than the letter A or the letter J or the exclamation point is just the character of four and it doesn't 比字母 A 或字母 J 或感叹号只是字符 4 而不是
know how to add a character of four to a number of three. 知道如何将一个字符四加到一个数字三上。
So we're going to see a big red flashing error message on the right here. 所以我们将在右侧看到一个大的红色闪烁错误消息。
It doesn't even matter what order we proceed and if we do something like four plus three as a string 无论我们以什么顺序进行，如果我们将四加三作为一个字符串来做，都没有关系
we're going to get the exact same error. 我们将得到完全相同的错误。
Ruby doesn't know how to combine a string plus a number. Ruby 不知道如何组合字符串和数字。
So watch out for that just because it outputs like a string doesn't mean that it is a string. 所以要注意它只是因为它输出像一个字符串并不意味着它是一个字符串。
Let's see what happens interestingly enough when we try to use the plus symbol to combine two strings 让我们看看当我们尝试使用加号来组合两个字符串时会发生什么有趣的事情
in the example above we did four plus three and we treated them as numbers. 在上面的示例中，我们做了四加三，并将它们视为数字。
What if we do something like string four plus string three. 如果我们做类似字符串 4 加字符串 3 的事情会怎样。
Both of those are written in double quotes so they're just being treated as characters. 这两个都是用双引号写的，所以它们只是被视为字符。
When I execute this you'll see that Ruby is going to output 43. 当我执行这个时，你会看到 Ruby 将输出 43。
And as you can probably guess what it's doing is taking those two strings and simply combining them 正如您可能猜到的那样，它正在做的是获取这两个字符串并将它们简单地组合起来
or smushing them on top of each other. 或将它们相互挤压。
In programming terms that's called concatenation. 在编程术语中，这称为串联。
That's basically what one string is appended or added to the end of another. 这基本上就是将一个字符串附加或添加到另一个字符串的末尾。
So what it's doing is taking that string of three and concatenating it to the end of the string of four 所以它正在做的是把那个三串串连接到四串串的末尾
and then outputting it to us in our avid runner. 然后在我们狂热的跑步者中将其输出给我们。
So how the plus symbol works is going to vary depending on whether you're using something like numbers 因此，加号的工作方式会有所不同，具体取决于您是否使用数字之类的东西
or integers and whether you're using strings. 或整数以及您是否使用字符串。
So watch out for that. 所以要当心。
Now to reiterate the most important thing to remember about puts is that it automatically adds a line 现在重申关于 puts 要记住的最重要的事情是它会自动添加一行
break at the end of every output that you do. 在您所做的每个输出结束时中断。
So so far we've had eight separate put statements so we've had eight line breaks that allows the next 到目前为止，我们有八个单独的 put 语句，所以我们有八个换行符，允许下一个
output to begin at the next line. 输出从下一行开始。
Here's where it gets really interesting. 这是真正有趣的地方。
You can actually use puts like this without actually giving it any thing to output. 您实际上可以像这样使用 put 而无需实际给它任何输出。
What this will do is output nothing. 这将做的是什么都不输出。
But remember that puts automatically as a line break to the end. 但请记住，将自动作为换行符放置到末尾。
So what puts by itself is going to do is simply add a line break. 所以 put 本身要做的只是添加一个换行符。
Now this may not be easily visible when I execute this but rest assured we've added an additional line 现在，当我执行此操作时，这可能不容易看到，但请放心，我们已经添加了额外的一行
break at the end of our output. 在我们的输出结束时中断。
So if I just let's say put another puts and another puts and now I'm just going to put this. 因此，如果我只是说放另一个看跌期权和另一个看跌期权，现在我就放这个。
See there's a bunch of line breaks above. 看到上面有一堆换行符。
When I execute this we can see that that line has appeared right here as a string. 当我执行此命令时，我们可以看到该行已作为字符串出现在此处。
And then we have all of these extra lines or empty lines right here from all of those puts methods that 然后我们从所有这些 puts 方法中得到所有这些额外的行或空行
we've called without any specific outputs. 我们打电话时没有任何具体的输出。
That puts better always adds a line break even when it doesn't output anything. 更好的是，即使它不输出任何内容，也总是会添加一个换行符。
That's what makes it unique. 这就是它的独特之处。
So as we proceed throughout the course whenever I'm going to break up different statements or different 因此，当我们在整个课程中进行时，每当我要分解不同的陈述或不同的
put statements just so we can read our output a little bit easier. put 语句只是为了让我们可以更容易地阅读我们的输出。
This is going to be a very common technique. 这将是一种非常普遍的技术。
I do simply to isolate the content so for example if I wanted to show you the difference between what 我只是为了隔离内容，例如，如果我想向您展示两者之间的区别
this results in and what this results in right here I might do something like put a puts right here 这会导致什么，这会导致什么，我可能会在这里做一些事情
and we can see there's a separator now between them an empty white line and we can see that those two 我们可以看到它们之间现在有一个分隔符，一条空白线，我们可以看到那两个
are separated. 分开了。
Sometimes it makes things a little bit easier to read and the output. 有时它会让事情更容易阅读和输出。
But that's a quick introduction to the puts method which outputs something to the screen and adds a 但这是对 puts 方法的快速介绍，该方法将一些内容输出到屏幕并添加一个
line break at the end. 最后换行。
And in the next lesson we'll explore the print method which is almost identical the only difference 在下一课中，我们将探索几乎相同的打印方法，唯一的区别
is printed does not include a line break. 打印不包括换行符。
So I'll see other. 所以我会看到其他的。