File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -11,11 +11,15 @@ def greet
1111puts greet
1212
1313# The return value can be explicitly declared as needed.
14- def greet_again
15- return greeting = "Yo"
14+ def greet_again ( cool = false )
15+ if cool
16+ return greeting = "Yo"
17+ end
18+ greeting = "Hello"
1619end
1720
18- puts greet_again
21+ cool = true
22+ puts greet_again ( cool )
1923
2024# The last statement has a conditional
2125# that when it is not met returns nil.
@@ -38,3 +42,13 @@ def add(number_1, number_2)
3842
3943puts add ( 8 , 3 )
4044
45+ # Multiple values can be returned in an array or hash.
46+ def add_and_subtract ( number_1 , number_2 )
47+ add = number_1 + number_2
48+ subtract = number_1 - number_2
49+ [ add , subtract ]
50+ end
51+
52+ # Multiple assignment can be used to take values out of an array and assign them to variables.
53+ add_result , sub_result = add_and_subtract ( 15 , 2 )
54+ puts "Addition result was #{ add_result } whilst subtraction was #{ sub_result } ."
You can’t perform that action at this time.
0 commit comments