- Comprehensive Ruby Programming
- Jordan Hudgens
- 223字
- 2021-07-02 21:13:33
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:
- The raw wood is placed in the machine.
- From there, the machine takes the wood, cuts, and polishes it.
- 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.
推薦閱讀
- HTML5+CSS3+JavaScript從入門到精通:上冊(微課精編版·第2版)
- Building a Home Security System with Raspberry Pi
- C語言程序設計
- Android底層接口與驅動開發技術詳解
- Clojure Reactive Programming
- 計算機應用基礎實踐教程
- Integrating Facebook iOS SDK with Your Application
- SQL基礎教程(第2版)
- INSTANT Sinatra Starter
- Internet of Things with ESP8266
- Spring+Spring MVC+MyBatis從零開始學
- Spring Boot實戰
- 超好玩的Scratch 3.5少兒編程
- 實驗編程:PsychoPy從入門到精通
- Docker on Windows