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

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.
主站蜘蛛池模板: 天台县| 栾城县| 德钦县| 庆元县| 淳化县| 乐至县| 井陉县| 龙陵县| 佳木斯市| 姚安县| 桃江县| 抚松县| 万山特区| 中山市| 五寨县| 诸暨市| 双流县| 陆良县| 定襄县| 海林市| 巴林左旗| 扶绥县| 汉沽区| 广灵县| 辉县市| 仲巴县| 改则县| 滨州市| 准格尔旗| 瓦房店市| 福州市| 兖州市| 吉林省| 和平县| 五家渠市| 新宾| 霍林郭勒市| 泽州县| 盐津县| 庄浪县| 准格尔旗|