Ruby Learning # 15 Methods

def sayhi puts "Hello User" end

sayhi

Hello User

puts "Top" sayhi puts "Bottom"

def sayhi(name,age) puts ("Hello" + name + ",you are " + age) end

sayhi("Mike",73)

error String type and Int type do not stick together. def sayhi(name,age) puts ("Hello" + name + ",you are " + age.to_s) end

sayhi("Mike",73)

Hello Mile ,you are 73

def sayhi(name="no name",age=-1) puts ("Hello" + name + ",you are " + age.to_s) end sayhi("Mike")

Hello Mike, you are -1 sayhi

Hello no name , you are -1

Recommended Posts

Ruby Learning # 15 Methods
Ruby Learning # 31 Object Methods
Ruby learning 4
Ruby learning 5
Ruby learning 2
Ruby learning 6
Ruby learning 1
Ruby Learning # 25 Comments
Ruby Learning # 1 Introduction
Ruby Learning # 34 Modules
Ruby Learning # 33 Inheritance
About Ruby methods
Ruby Learning # 30 Initialize Method
Ruby learning points (basic)
Ruby Learning # 29 Classes & Objects
Ruby Learning # 24 Exponent Method
Ruby Learning # 17 If Statements
Ruby Learning # 21 While Loops
Ruby Learning # 27 Writing Files
About Ruby instance methods
Ruby variables and methods
[Ruby] methods, instance methods, etc ...
Ruby Learning # 28 Handling Errors
Ruby Learning # 26 Reading Files
Ruby Learning # 23 For Loops
Ruby Learning # 16 Return Statement
[Learning Memo] Metaprogramming Ruby 2nd Edition: Chapter 3: Methods
Ruby Learning # 2 Drawing a Shape
Basic methods of Ruby hashes
Ruby on rails learning record -2020.10.03
Basic methods of Ruby arrays
Ruby on rails learning record -2020.10.04
Ruby on rails learning record -2020.10.09
Ruby Learning # 18 If Statements (Con't)
Ruby on Rails basic learning ①
Ruby Learning # 11 Building a Calculator
Ruby Learning # 99 Personal Programming Notebook
Ruby on rails learning record-2020.10.07 ②
Three Bit Manipulation Methods (Ruby)
Ruby Learning # 10 Getting User Input
Ruby Learning # 32 Building a Quiz
Ruby Learning # 8 Working With String
What are Ruby class methods?
Ruby on rails learning record-2020.10.07 ①
Ruby on rails learning record -2020.10.06
[Ruby] Singular methods and singular classes
[Ruby] Class methods, instance methods, etc.
Ruby variables and functions (methods)
Ruby methods and classes (basic)
[Ruby] Singular methods and singular classes
Ruby Learning # 19 Building a Better Calculator
Write Ruby methods using C (Part 1)
Ruby standard input and various methods
Completed Progate Ruby Learning Course II
Ruby convenience methods for fledgling engineers
Ruby Learning # 22 Building a Guessing Game
[Ruby] Handle instance variables with instance methods
Ruby methods often used in Rails
Java learning (0)
[Ruby] Array
Java methods