[Ruby] Method that returns truth

Progate learning notes Write a conditional expression in the return value of the method so that the truth is returned.

def shipping_free?(price)
  return price >= 3000
end

** Methods that return a boolean value have the convention of adding a "?" To the end of the method name. ** ** This method is true if the price is 3000 or higher, Returns false if price is less than 3000

When incorporated in an if statement, it looks like this

if shipping_free?(4000)
  puts "Free shipping."
else
  puts "A shipping fee of 500 yen will be charged."
end

The result of executing this is

Free shipping.
``

---
reference:[Progate](https://prog-8.com)


Recommended Posts

[Ruby] Method that returns truth
Ruby to_s method
[Ruby] end_with? method
[Ruby] Method memorandum
[Ruby] initialize method
Ruby build method
Ruby accessor method
ruby map method
Ruby Learning # 30 Initialize Method
abbreviation for ruby method
Ruby Learning # 24 Exponent Method
Ruby Thread # [] = method notes
definition of ruby method
[Ruby] Method definition summary
Integer check method with ruby
Ruby algorithm (inject, method definition)
Arrays.asList method returns not java.util.ArrayList
[Ruby] Notes on gets method
[ruby] Method call with argument
Consider implementing a method that returns the difference between two Lists
[Ruby] Use an external API that returns JSON in HTTP request
[Ruby] Method to count specific characters
[Ruby] present/blank method and postfix if.
[Ruby] Extracting elements with slice method
[Ruby basics] split method and to_s method
[Ruby] How to use any? Method
String output method memo in Ruby
Was that so, the user_signed_in? method
[Ruby on Rails] Convenient helper method
[Ruby] undefined method `dark?'occurs in rqr_code
How to use Ruby inject method