[RUBY] Output about the method Part 1

Output about the method!

I knew it in my head, but can I explain it again? The real intention is that it is a little difficult to say.

I would like to re-recognize it while thinking in words to deepen my understanding.

Let's start the output! !!

What is a method?

Simply put, a mass of processing? It's like that. `def, method name (please decide.) Line break Write a process, start a new line Write end. ``

method.rb


def method name
Write the process here
end

What do you use it for? For example, in the case of do not use methods to process calculations

sample.rb



eraser = 110
pen = 150

puts eraser + pen

And with use the method ...

sample.rb


def addition
  eraser = 110
  pen = 150
  eraser + pen
end

puts addition

It will be.

If it's simple, you won't feel the meaning or benefit of using the method. But when the process gets complicated, you can feel the tremendous benefits! !!

Various processes such as if can be described in the method. For example ...

sample.rb


def register
  eraser = 110
  pen = 150
  bill = eraser + pen
  if bill >= 200 #10 for purchases over 200 yen%off!!
    bill * 0.9
  end
end
  puts register #Call the register method.

And, like this, it will calculate and discount with one method (lump).

That's all for today's output. I think it will continue until the second and third.

Recommended Posts

Output about the method Part 1
Output about the method # 2
About the method
About the length method
About the authenticate method.
About the map method
About the ancestors method
[Output] About the database
About the to_s method.
about the where method (rails)
Consideration about the times method
About the role of the initialize method
[Output] About each
About the package
Output of how to use the slice method
About No Method Error
About the StringBuilder class
Commentary: About the interface
About the asset pipeline
About the function double-java
About Java method binding
About the ternary operator
About method splitting (Java)
static factory method part 1
About the Kernel module
About the [ruby] operator
About the handling of Null
About specifying the JAXRS path
What is the pluck method?
A note about the scope
[Ruby] Questions and verification about the number of method arguments
About the description of Docker-compose.yml
About the File :: Stat class
I want to expand the clickable part of the link_to method
[Java Silver] About equals method
Understand the helper method form_with
About the same and equivalent
About the Android life cycle
About the explanation about functional type
About the programming language Crystal
About Rails scraping method Mechanize
What is the initialize method?
Introduction to swift practice output Type representing the Chapter 4 collection Part 1
Introduction to swift practice output Type representing the Chapter 4 collection Part 2
Connecting to a database with Java (Part 1) Maybe the basic method
I don't understand the devise_parameter_sanitizer method, so I'll output it here.
How to use the link_to method
About the behavior of ruby Hash # ==
Qualify only part of the text
Simulate the simplex method with GUI
How to use the include? method
How to use the form_with method
About the basics of Android development
[Rails] About the Punk List function
About the equals () and hashcode () methods
About the symbol <%%> in Rails erb
About the information sharing app band
Java comparison using the compareTo () method
About the current development environment (Java 8)
I tried to explain the method
String output method memo in Ruby