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

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.
主站蜘蛛池模板: 九台市| 宝鸡市| 崇文区| 延津县| 忻城县| 来安县| 永仁县| 铁岭县| 平塘县| 兴国县| 祁连县| 栾川县| 璧山县| 库伦旗| 边坝县| 广平县| 将乐县| 乐业县| 靖州| 新建县| 荔波县| 额济纳旗| 凤冈县| 喜德县| 子长县| 洛隆县| 南雄市| 农安县| 西丰县| 临安市| 民县| 德保县| 沁水县| 库尔勒市| 岢岚县| 东乌| 洛川县| 南岸区| 政和县| 佛学| 威远县|