How to use the include? method

This article uses Ruby 2.6.5 installed on macOS Catalina 10.15.6. I have summarized the include? method in my own way.

include? Method

--Method to judge whether the element specified by the argument is included in the array or character string

array = ["dog", "cat"]
puts array.include?("dog") # => true
puts array.include?("hoge") # => false

In the actual code

--Output example: Enter the name you want to register (Example) Yamada Taro ――In this case, you want to receive the entered name and output an error statement if there is a "." Or "blank".

def check_name(name)
  if name.include?(".")
    puts "!error!Symbols cannot be registered"
  elsif name.include?(" ")
    puts "!error!Blanks cannot be registered"
  else
    puts "Registration has been completed"
  end
end

puts 'Please enter the name you want to register'
name = gets
check_name(name)

--In the second line, include in the argument name of the check method? If there is an argument "." (Period) in, true is returned and an error statement is output. --Similarly, if there is an include? Argument "" (blank) in name, true is returned and an error statement is output.

Recommended Posts

How to use the include? method
How to use the form_with method
[Rails] How to use the map method
[Java] How to use the toString () method
Output of how to use the slice method
How to use the replace () method (Java Silver)
[Ruby basics] How to use the slice method
[Java] How to use join method
How to use the wrapper class
[Ruby] How to use any? Method
How to use Ruby inject method
How to use the getter / setter method (in object orientation)
[Java] How to use the File class
[Java] How to use the hasNext function
How to use submit method (Java Silver)
[Java] How to use the HashMap class
Studying how to use the constructor (java)
[Processing × Java] How to use the loop
[Processing × Java] How to use the class
[Processing × Java] How to use the function
[Java] How to use the Calendar class
[Rails] How to use helper method, confimartion
How to use Map
How to use rbenv
How to use letter_opener_web
How to use with_option
How to use fields_for
How to use java.util.logging
How to use map
How to use collection_select
How to use Twitter4J
How to use active_hash! !!
How to use MapStruct
How to use hidden_field_tag
How to use TreeSet
[How to use label]
How to use identity
How to use hashes
How to use JUnit 5
How to use Dozer.mapper
How to use Gradle
How to use org.immutables
How to use java.util.stream.Collector
How to use VisualVM
How to use Map
How to use the camera module OV7725 (ESP32-WROVER-B)
[Java] How to use Thread.sleep to pause the program
[Ruby] How to use gsub method and sub method
When you want to use the method outside
[Ruby on Rails] How to use session method
[Java] How to use Map
How to use Chain API
[Java] How to use Map
How to use Priority Queuing
[Rails] How to use enum
How to use java Optional
How to use JUnit (beginner)
How to use Ruby return
[Rails] How to use enum
How to use @Builder (Lombok)
[Swift] How to use UserDefaults