Step 3 / Select topic Ruby Medium

What this bank covers

  • Ruby `*` is receiver-dependent
  • Proc vs lambda: argument binding and return
  • Ruby truthiness
  • Integer vs Float division
  • Integer division and modulo in Ruby
  • The spaceship operator and incomparable types
  • == versus eql? for numbers
  • Integer division truncates the remainder
  • Integer division floors toward negative infinity
  • Ruby's % takes the sign of the divisor
  • Floats are binary approximations
  • Rounding with negative digits
  • to_i truncates, floor and ceil go in fixed directions
  • Float division by zero
  • Math.sqrt versus Integer.sqrt
  • Rational arithmetic is exact and normalised
  • Float#round and the half: option
  • sub replaces only the first match
  • Plain string literals are mutable by default
  • String#* repeats the string
  • split keeps interior empty fields
  • Bang string methods return nil when nothing changes
  • Single quotes do not interpolate
  • center pads both sides
  • Negative start index with a length
  • tr translates characters positionally
  • String#tr character translation
  • each_with_object returns the memo object
  • with_index accepts a starting offset
  • Lazy enumerators work on infinite sequences
  • Enumerable builds everything on top of each
  • zip pads with nil using the receiver's length
  • each_cons yields overlapping windows
  • chunk_while groups by comparing neighbours
  • External iteration with Enumerator#next and #rewind
  • Enumerable is built on a single each method
  • each_slice returns an Enumerator of fixed-size groups
  • Hash.new(0) as a counter
  • The shared default object trap
  • Array as both stack and queue
  • Array#delete removes every match
  • Set union, intersection and difference
  • String keys are duplicated and frozen
  • flatten with and without a depth limit
  • Binary search in find-minimum mode
  • Reversing a linked list built from Struct nodes
  • Ruby hashes keep insertion order
  • Default arguments see earlier parameters
  • def is a scope gate
  • Block-local variables with the semicolon list
  • Splat, keyword, and double-splat parameters
  • define_method closes over the enclosing scope
  • Lambdas sharing a captured local variable
  • return inside a block exits the enclosing method
  • Optional blocks, yield, and &:symbol
  • ensure does not change the return value
  • An explicit return inside ensure wins
  • retry restarts the begin block
  • Bare rescue only catches StandardError
  • throw/catch for non-local exit
  • Rescue clauses are matched top to bottom
  • next supplies the block's value
  • loop rescues StopIteration
  • The inline rescue modifier
  • Unwinding order of nested ensure and rescue
  • Mutex#synchronize protecting a shared counter
  • Exceptions escaping a thread
  • Queue as a thread-safe FIFO channel
  • Ruby's Mutex is not reentrant
  • Fiber resume and Fiber.yield interleaving
  • Thread#status for a normally terminated thread
  • Thread#value joins and returns the block result
  • Thread.current[] is per-thread storage
  • Closing a Queue drains then returns nil
  • Values flow both ways through Fiber.yield
  • In-place append vs. reassignment
  • The nil pitfall in ||= memoization
  • Array#include? is O(n)
  • Lazy enumerators do only the work you consume
  • flat_map avoids the intermediate array
  • Integer#pow with a modulus
  • sort_by computes each key once
  • Range#bsearch is logarithmic
  • Memoizing recursion with a Hash default block
  • String += allocates, << mutates in place
  • Array.new with a default value shares one object
  • Hash.new(default) returns a shared, unstored default
  • `and` has lower precedence than assignment
  • String#succ carries across letter and digit classes
  • Exponentiation precedence and associativity
  • Array.new default value versus block
  • Splats in multiple assignment
  • Spaceship operator with incomparable types
  • === is not symmetric
  • != is derived from ==
  • Result types of numeric operators
  • prepend places a module before the class in the ancestor chain
  • Array#* dispatches on argument type
  • Method bodies open a new local scope
  • Ruby format flags: zero-pad, forced sign, hex