[RUBY] Output about the method # 2

Method output part 2 argument

In Part 1, I tried using an if statement inside the method.

* This is the previous article. Output about the method 1

This time I'd like to use arguments to make the code a little cleaner!

This is the previous code.

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.

this Let's define the numbers for eraser and pen outside the method.

sample.rb


def register
  eraser = 110 #Numerical value here
  pen = 150 #Numerical value here
  bill = eraser + pen
  if bill >= 200
    bill * 0.9
  end
end
  puts register

Add () after def register and inside it I'll put in eraser and pen.

sample.rb


def register(eraser, pen) #Comma between eraser and pen(,)And half-width space
  # eraser =110 Delete here
  # pen =150 Deleted here
  bill = eraser + pen
  if bill >= 200
    bill * 0.9
  end
end
  puts register(150, 100) #Put a number here

puts register (150, 100) These two numbers are def register (eraser, pen) Sent here. Each eraser is 150 pen is 100 Will be sent.

sample.rb


def register(eraser, pen)
  bill = eraser + pen
  if bill >= 200
    bill * 0.9
  end
end

puts register(150, 100)

It's just a little cleaner! (Maybe)

It was today's output. : sweat:

Recommended Posts

Output about the method # 2
Output about the method Part 1
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
About Java log output
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)
Output of how to use the slice method
About the Kernel module
About the [ruby] operator
About the handling of Null
About specifying the JAXRS path
Note the StringUtils # containsAny method
What is the pluck method?
A note about the scope
About the description of Docker-compose.yml
About the File :: Stat class
[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?
[Ruby] Questions and verification about the number of method arguments
About the behavior of ruby Hash # ==
Simulate the simplex method with GUI
Method
About the language to be learned
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
A murmur about the utility class
[Rails] About helper method form_with [Basic]
Think about the 7 rules of Optional
About =