Skip to content

Instantly share code, notes, and snippets.

@Jecacueca
Created March 19, 2024 10:14
Show Gist options
  • Save Jecacueca/4194e2e368aeb5f4b7528dc2efd320d9 to your computer and use it in GitHub Desktop.
Save Jecacueca/4194e2e368aeb5f4b7528dc2efd320d9 to your computer and use it in GitHub Desktop.
# # *assigning* the value of 29 to the variable age
age = 29
puts age
# *reassign* the value of age
puts "one year passes..."
age += 1
puts age
# call one variable from within another
city = "paris"
city_details = "I'm going to holiday to #{city}"
puts city_details
# require date class from Ruby -> this one is not built in by standard
require 'date'
# THINGS TO THINK ABOUT WHEN DEFINING METHODS
# 1. Name of the method
# 2. Does it take any paramters? How many?
# 3. What does it return
def say_hi(name) # parameters are placeholder for real data
return "Good Morning #{name} :)"
end
puts say_hi("jess") # argument -> is the real we want to feed to the method
# I can call one method many times
puts say_hi("Paul")
puts say_hi("George")
puts say_hi("Ringo")
puts say_hi("John")
def full_name(first_name, last_name)
return "Hello, #{first_name} #{last_name}"
end
# calling method with fixed arguments
puts full_name("jess", "silva")
# methods + variables
# WE WANT A USER INPUT for arguments
puts "Give us your first name.."
first_name = gets.chomp # stores user input to first_name
puts "Give us your last name.."
last_name = gets.chomp # stores user input to last_name
puts full_name(first_name, last_name) # pass variables as arguments to the method
# Method with no parameter
def tomorrow
tomorrow = Date.today + 1
return tomorrow.strftime("%A, %b %d")
end
puts tomorrow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment