-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex21 - start with function.rb
37 lines (28 loc) · 1.13 KB
/
ex21 - start with function.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# what is Function?
# function is a block of code can i use that multiple times throughout the program. by calling
# the name of function and not write the all of code one more time. it is more easy to read and
# understand, easy to maintain and easy to debug it. Functions can accept input parameters,
# allowing them to work with different data or perform variations of the same task.
# Parameters provide flexibility and allow functions to be more versatile. Functions can
# optionally return a value after performing their task. This enables functions to produce
# output that can be used by other parts of the program.
# ########
# Parameters?
# Is a list of inputs or data values that the program send to the function for make the processing on. (optional)
# Built-In Functions In Ruby
sum = (1..10).sum
puts sum
power = 5.pow(2)
puts power
floor = 12.40.floor
puts floor
length = "Ahmed".length
puts length
size = "Ahmed".size
puts size
include = "Mostafa Mohamed Ahmed".include?("Ahmed")
puts include
start_with = "Mostafa Mohamed Ahmed".start_with?("Mostafa")
puts start_with
end_with = "Mostafa Mohamed Ahmed".end_with?("Ahmed")
puts end_with