Ruby Part 5

Ruby Methods

Introduction

def prime?(n)
    Prime.prime?(n)
end

Arguments

def take(arr, n)
    arr.shift(n)
    return arr
end

Variable Arguments

def full_name(first, *middle, last)
    if middle.empty?
        return first.to_s + " " + last.to_s
    else
        return first.to_s + " " + (middle * " ") + " " + last.to_s
    end
end

Jenny Plunkett

Applications Engineer @ Arm