Skip to content

Instantly share code, notes, and snippets.

@mlabisi
Created November 5, 2019 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlabisi/a01af168c19b080546c889aa3e693907 to your computer and use it in GitHub Desktop.
Save mlabisi/a01af168c19b080546c889aa3e693907 to your computer and use it in GitHub Desktop.
For C2
#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