A collection of answers to the most popular Ruby & Rails quizzes we share on social media.
Each entry comes with a clear explanation so you can dive deeper into tricky behaviors and sharpen your skills.
1396 views
We begin with a simple string instance and attach a singleton method to it. Only that instance...
1618 views
r = (1.0..3.0) r === 3 At first sight you might think that the comparison will...
3028 views
In Ruby, the ability to define default argument values for method parameters is a flexible...
1563 views
A method that never yields ignores the block. Constants reveal the truth and make the behavior easy to see.
1427 views
Quoted delimiters turn off interpolation and escapes. Great for snippets that must be preserved exactly as written.
1251 views
The guard prevented the class body from running, so to_s is the default. A quiet lesson about where to place conditions.
1521 views
Some conversions are forgiving and others raise. Learn the exact behavior so your guards are tight and your code reads clean.
1254 views
instance_of? does not walk the hierarchy. For inheritance aware checks use is_a? and keep intent honest.
1252 views
Ruby evaluates && before ||. The final string can surprise you. Master the order and your boolean logic reads well.
1667 views
Adding the same tag twice changes nothing. The set stays unique and sorted, which is perfect for tidy tag lists.
1807 views
Ruby lets you interpolate instance variables without braces. A tiny to_s becomes clean and pleasant to read.
1453 views
Including a module brings its constants into scope until you define a new one with the same name. Then Ruby resolves to yours.
1790 views
When a string is already uppercase, upcase! returns nil. Chaining fails. Learn when to choose the non bang version.
1251 views
A block assignment writes into the existing local variable. After the block, the outer value reflects the inner change.
1562 views
invert swaps keys and values, then replace keeps the swap. Looking up by the old key will not work anymore.
1720 views
Assigning into a zero length slice inserts without replacing. A precise way to transform arrays where they sit.
1684 views
Assign a hash to itself and you get recursion. Index through it and watch the same object lead you back to the leaf value.
2000 views
case stops at the first match. Even identical branches do not stack. The first hit wins and the result is simple to reason about.
1674 views
Bang methods may return nil when no change happens. Chaining then fails. Learn a tidy pattern that keeps your code robust.
2398 views
See how Ruby handles an array that contains itself. A curious case that reveals how flatten avoids infinite recursion with grace.
1811 views
Stop an iteration and surface the match in a single move. It is a tidy pattern that reads well and saves extra variables.
1356 views
Fix a message or regroup your work without losing progress. Learn the exact command that resets the commit while keeping files staged.
2377 views
Unlike each with a block, a for loop writes to the outer scope. After the loop, i holds the last value.
1639 views
A lambda returns to its caller. A proc returns from the method that defined it. This contrast shapes control flow in real apps.
1969 views
A shared default leaks across keys. Switch to a block default and each key gets its own fresh array. Clean and predictable.
1981 views
A block default returns a fresh array each time but you still need to store it. Learn the safe pattern that avoids leaks.
2013 views
Array indexing expects integers. A float index triggers coercion rules and a result that sharpens your sense of types.
2290 views
Identity hashes compare keys by object id. Two equal strings are not the same key unless they are the same object.
3687 views
When a symbol and a string key collide, the symbol wins and the last assignment stands. A crisp reminder of Rails hash semantics.
1773 views
Lots of punctuation can hide a simple idea. Peel the not operators one by one and the final truth pops out.
2048 views
cycle creates an endless playlist. After two steps the next call wraps around. Perfect for toggles and round robin flows.
1755 views
Ruby splits numbers from the right. A playful method that invites tiny math tricks and clear thinking about order.
1822 views
Use a tiny idiom to filter out nil and false while keeping zeros and empty strings. It feels like magic and makes your intent obvious.
1747 views
Rendering twice causes trouble. Halt after the first response or redirect to keep controller actions clear and correct.
4465 views
The guarded assignment does not run, so the method call wins. A neat tour through name resolution inside methods.
1431 views
Discover why 1.0 == 1 is true while eql? and equal? are not. Learn how Ruby separates identity, strict equality, and value to keep intent clear.
2590 views
Freezing does not change how hashes enumerate. Splat a hash and you get tidy key value pairs ready to use.
3411 views
When you pass both a replacement and a block, Ruby picks the string. A small rule that explains big surprises in real code.
1662 views
Hop through arrays and strings in one chain. It feels like spelunking through data until you land on a single character.
1599 views
Ruby swaps variables without a temp. It is clean, expressive, and a joy to teach. One line and you are done.
3990 views
Union preserves order and uniqueness from the left side. Watch duplicates vanish while the first appearance sets the tone.
1254 views
Alias at the class level can capture a method before overrides apply. Timing changes which behavior a new name points to.
1853 views
Operators are methods. Even ! can be invoked in sequence on numbers. It looks odd, but it teaches real lookup rules.
1428 views
Generate a quick snapshot of your codebase from the command line. It is a fast ritual before refactors and releases.
1778 views
The star operator repeats an array or joins it with a string. A tiny move that builds readable output fast.
2451 views
A block may run twice or more. Plan for side effects and write blocks that behave well when invoked again.
1941 views
Methods inside a false guard never exist. The call fails because the class body did not run. A gentle reminder to keep guards outside.
1556 views
Compose tiny functions like building blocks. Follow the data as it flows through dec, dbl, and inc for a satisfying result.
1621 views
Pass a frozen array without fear. The += operator builds a new array, so the original stays untouched and safe.
2231 views
Side effects happen on demand with lazy enumerators. Trace each step and feel the evaluation order click into place.
5635 views
Appending to a frozen string creates a new object. Learn how Ruby protects immutability while keeping code pleasant to write.
RubyCademy ©