Ruby Part 2

Ruby Control Stuctures

Each

def scoring(array)
    array.each do |user|
        user.update_score
    end
end

Unless

def scoring(array)
    array.each do |user|
        unless user.is_admin?
            user.update_score
        end
    end
end

Infinite Loop

loop do
    coder.practice
    break if coder.oh_one?
end

Until

coder.practice until coder.oh_one?

Case (Bonus Question)

def identify_class(obj)
    case obj
    when Hacker
        puts "It's a Hacker!"
    when Submission
        puts "It's a Submission!"
    when TestCase
        puts "It's a TestCase!"
    when Contest
        puts "It's a Contest!"
    else
        puts "It's an unknown model"
    end
end

Jenny Plunkett

Applications Engineer @ Arm