Quiz: Ruby
Ruby questions from real interviews as a quiz, with an explanation for every option.
Try it: 5 questions
Loading…
Sample questions
What are Docker multi-stage builds used for?
- To automatically run an application in several containers from a single Dockerfile.
- To combine several Docker images into one while retaining all their files and dependencies.
- To replace a dependency manager and install Ruby libraries without Bundler.
- To build an application in one stage and copy only the runtime artifacts into the final image.
Which statements correctly describe a Ruby
Hash? Select all that apply.- Only symbols can be used as keys.
- It preserves the order in which entries were added.
- It stores key-value pairs, and values are accessed by key.
- It provides fast average lookup by key.
- It can only be accessed by numeric index, like an array.
Which statement about PostgreSQL index types is correct?
- Hash is general-purpose and used by default; B-tree is suited only to equality comparisons.
- GIN is general-purpose and used by default; GiST is suited only to full-text search.
- BRIN is general-purpose and used by default; SP-GiST is intended only for equality.
- B-tree is general-purpose and used by default; Hash is suited to equality comparisons.
What happens if Ruby evaluates
MyStringbefore a constant with that name has been defined?- It raises
SyntaxErrorbecause constant names cannot containString. - Ruby returns
nil, as it does for a missing value. - Ruby automatically creates the string
"MyString". - It raises
NameError: uninitialized constant MyString.
- It raises
What is TCP/IP?
- A routing protocol that chooses the shortest path for every packet.
- A standard for physically connecting devices with Ethernet cables.
- A data transfer protocol that always guarantees packets arrive in order.
- A suite of network protocols for exchanging data between devices on the internet and local networks.
In Ruby, what are the arguments passed when creating an instance with
ClassName.new(...)?- Values passed to
Class.newto declare class methods. - Values that the
newmethod returns after creating an instance. - Local variables declared inside the class body.
- Values that
newpasses toinitializeto configure the new object.
- Values passed to
When does Rails create a controller instance, and how long is it used?
- On the first visit to the controller; until the process restarts
- After rendering the response; until the next request arrives
- When the application starts; until it shuts down
- After routing the request; to handle that request
How do threads work with the Global VM Lock (GVL) in MRI Ruby?
- Only one thread executes Ruby code at a time, but blocking I/O can release the GVL.
- Each thread gets its own GVL and executes Ruby code in parallel.
- The GVL prevents thread switching even while a thread waits for I/O.
- MRI threads execute CPU-bound Ruby code in parallel, while the GVL limits only I/O.
Which practices can help maintain database performance as the data volume grows? Select all that apply.
- Normalize every table as much as possible because normalization always speeds up reads.
- Create an index on every column regardless of the queries.
- Analyze slow queries and their execution plans, for example with
EXPLAIN. - Cache frequently requested data when that fits the data-freshness requirements.
- Create indexes for fields frequently used in
WHERE,JOIN, andORDER BY.
All else being equal, which usually has greater overhead: calling a block or lambda in the current Ruby process, or creating a separate process with
Process.fork?- Creating a separate process
- Calling a block
- All three have roughly the same overhead
- Calling a lambda