wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Ruby Fall25-26

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Ruby loves blocks. Which is the correct way to pass a block to an each method?

a)

array.each[ |x| puts x ]

b)

array.each { |x| puts x }

c)

array.each do puts x end

d)

array.each (x) -> puts x

2.

What does this code print?

my_proc = Proc.new { |x| puts "I got #{x}" }

my_proc.call

a)

I got nil

b)

Error: wrong number of arguments

c)

Nothing

d)

I got

3.

What’s the difference between a Proc and a Lambda when arguments don’t match?

a)

Both throw errors

b)

Proc ignores, Lambda complains

c)

Lambda ignores, Proc complains

d)

Neither cares

4.

What happens if you use return inside a Proc defined in a method?

a)

Returns from Proc only

b)

Returns from the whole method

c)

Crashes Ruby

d)

Calls your parents

5.

What does this code print?

puts Time.new(2026,1,1).sunday?

a)

True

b)

False

c)

nil

d)

Depends on your laptop clock

6.

Which of these gives you the current time?

7.

fun = Proc.new { puts "Ruby Rocks!" }

fun.___

Fill in the blank:

a)

start

b)

execute

c)

run

d)

call

8.

How do you create a Lambda in Ruby?

a)

Lambda -> { }

b)

lambda { } or -> { }

d)

proc(lam) { }

9.

What will this print?

def movie_night

yield "Popcorn"

end

movie_night { |snack| puts "Enjoy your #{snack}!" }

a)

Enjoy your snack!

b)

Error: no block given

c)

nil

d)

Enjoy your Popcorn!

10.

If today is 2025-09-04, what will this print?

puts (Time.now + 60*60*24*7).strftime("%A")

a)

Today’s weekday name

b)

Time travel not supported

c)

Next week’s weekday name

d)

Error