官术网_书友最值得收藏!

What are method arguments?

Before we can get into the code examples, let's first walk through what method arguments are. Let's begin with a real-world example:

Imagine that you have a machine that makes baseball bats. The workflow for the bat making process would be as follows:

  1. The raw wood is placed in the machine.
  2. From there, the machine takes the wood, cuts, and polishes it.
  3. Lastly, it finishes off by giving the output as the finished baseball bats from the machine.

So let's see how this analogy applies to the methods in Ruby:

  • Method arguments: The raw wood placed inside the machine represents the method arguments. This is the data that can be provided by a user, a database query, an API, and so on. It is rare for a method not to have arguments, since method arguments are what allow for dynamic behavior. Looking back at our example, would it be possible to produce the baseball bats if we didn't first supply the machine with the raw materials? Of course not. In the same way, methods need data in order to work with.
  • The method: The machine itself represents the method. This is where the actual logic goes that will produce the desired behavior.
  • The returned values: Lastly, the finished bats are like the values that get returned by the methods.
主站蜘蛛池模板: 杭锦后旗| 关岭| 怀宁县| 郯城县| 伊宁市| 许昌市| 哈密市| 高淳县| 扶沟县| 资中县| 凉城县| 梁平县| 育儿| 庄河市| 建昌县| 开化县| 汤阴县| 黄石市| 祁东县| 沈丘县| 永泰县| 永和县| 宁蒗| 镇坪县| 庄浪县| 庄浪县| 曲水县| 师宗县| 雅江县| 洛南县| 高密市| 沛县| 南投县| 高尔夫| 犍为县| 鹤岗市| 威信县| 南靖县| 泸西县| 辽阳县| 甘孜县|