Skip to content

Instantly share code, notes, and snippets.

@phlipper
Created April 4, 2015 21:49
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 phlipper/02fee1a3ea09bc026ba0 to your computer and use it in GitHub Desktop.
Save phlipper/02fee1a3ea09bc026ba0 to your computer and use it in GitHub Desktop.
TECH603 Day 4 Warmup
# example used in warmup quiz
def function(a, b = 1)
a = a.to_i
if a == 1
a + 5 / 2
elsif a == 2
a + 5 + 3
elsif a > 2 && a <= 1000
a
end
end
# What is the result of calling function with the number 1?
function(1)
# What is the result of calling function with the number 2?
function(2)
# What is the result of calling function with the number 3?
function(3)
# What is the result of calling function with the number 5?
function(5)
# What is the result of calling function with the number 523?
function(523)
# What is the result of calling function with the number 2.6?
function(2.6)
# What is the result of calling function with the number 999?
function(999)
# What is the result of calling function with the number 1000?
function(1000)
# What is the result of calling function with the number 1001?
function(1001)
# What is the result of calling function with the string "one"?
function("one")
# What is the result of calling function with a nil value?
function(nil)
# What is the result of calling function with no argument?
function
# example using `case` with a fall-through `else`
def function_with_case(a, b = 1)
a = a.to_i
case a
when 1
a + 5 / 2
when 2
a + 5 + 3
when 3..1000
a
else
"hi"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment