Created
November 5, 2019 18:44
-
-
Save mlabisi/a01af168c19b080546c889aa3e693907 to your computer and use it in GitHub Desktop.
For C2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Single line comment | |
=begin | |
Multiple line | |
Comments | |
=end | |
def say_hello(name) | |
#with out new line | |
print "Hello, " | |
# with new line | |
puts "#{name}" | |
puts "Welcome to Ruby!" | |
end | |
#without return | |
def add2(num) | |
num+2 | |
end | |
def isConsecutive(array) | |
lastNum = array[0] | |
array[1, array.count].each do |num| | |
if lastNum != num - 1 | |
return false | |
end | |
lastNum = num | |
end | |
return true | |
end | |
#with return | |
def getSum(array) | |
result = array.inject(0){|sum,x| sum + x } | |
return result | |
end | |
say_hello('Everyone') | |
puts add2(2) | |
array = [1,2,3] | |
puts isConsecutive(array) | |
puts getSum(array) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment