0
0
Rubyprogramming~10 mins

IRB for interactive exploration in Ruby - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start the interactive Ruby shell (IRB).

Ruby
system('[1]')
Drag options to blanks, or click blank then click option'
Airb
Bruby
Crails
Dgem
Attempts:
3 left
💡 Hint
Common Mistakes
Typing 'ruby' instead of 'irb' starts the Ruby interpreter but not the interactive shell.
Using 'rails' or 'gem' commands won't open IRB.
2fill in blank
medium

Complete the code to assign the value 10 to variable x inside IRB.

Ruby
x [1] 10
Drag options to blanks, or click blank then click option'
A==
B!=
C=
D=>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' which is a comparison operator, not assignment.
Using '=>' which is used in hashes, not for assignment.
3fill in blank
hard

Fix the error in the IRB command to print 'Hello World'.

Ruby
puts [1]Hello World[1]
Drag options to blanks, or click blank then click option'
A"
B'
C`
D:
Attempts:
3 left
💡 Hint
Common Mistakes
Using backticks which execute shell commands.
Using colon which is invalid syntax here.
4fill in blank
hard

Fill both blanks to create a hash with key :name and value 'Alice' in IRB.

Ruby
person = [1] => [2]
Drag options to blanks, or click blank then click option'
A:name
B"Alice"
C'Alice'
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using plain word 'name' without colon for key.
Using double quotes for key which is less common for symbols.
5fill in blank
hard

Fill all three blanks to create an array of numbers from 1 to 5 and print each number in IRB.

Ruby
numbers = ([1]..[2]).to_a
numbers.each do |[3]|
  puts [3]
end
Drag options to blanks, or click blank then click option'
A1
B5
Cnum
Di
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or 6 instead of 1 or 5 for range boundaries.
Using 'i' as block variable when 'num' is expected here.