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

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.
主站蜘蛛池模板: 凤台县| 万宁市| 平舆县| 汉寿县| 嘉义市| 河南省| 内江市| 平定县| 丹江口市| 牙克石市| 防城港市| 英吉沙县| 鄂伦春自治旗| 襄汾县| 鄂州市| 东方市| 红原县| 和顺县| 泽库县| 临西县| 邳州市| 鸡东县| 友谊县| 巢湖市| 乐平市| 砀山县| 司法| 伊吾县| 称多县| 芦溪县| 荣昌县| 开江县| 无棣县| 东台市| 静乐县| 巴东县| 涿州市| 大渡口区| 彭泽县| 云龙县| 宜春市|