Skip to content

Instantly share code, notes, and snippets.

@phlipper
Created April 4, 2015 21:49
Show Gist options
  • Select an option

  • Save phlipper/02fee1a3ea09bc026ba0 to your computer and use it in GitHub Desktop.

Select an option

Save phlipper/02fee1a3ea09bc026ba0 to your computer and use it in GitHub Desktop.

Revisions

  1. phlipper created this gist Apr 4, 2015.
    65 changes: 65 additions & 0 deletions warmup.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@
    # 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