require 'benchmark' # A major difference from the previous # benchmark is that in order to measure # the performance of method creation # (as opposed to method execution), we're # ensuring that we create a new method in # each iteration of the benchmark loop class Monk def with_eval(u...

Related:

Example Code: class Item def initialize(item_name, qty) @item_name = item_name @qty = qty end end item = Item.new("a",1) puts item p item [reset] Need a hint? See the Solution Hint Output Window As you can see, puts prints the class name of the object along with a number displayed as ...

A lambda is a piece of code that you can store in a variable, and is an object. The simplest explanation for a block is that it is a piece of code that can't be stored in a variable and isn't an object. It is, as a consequence, significantly faster than a lambda, but not as versatile ...

Blocks are often the first Ruby-ism that new Rubyists run into, and are confused by. What are blocks? Why do they exist? How do I use them? I'll do my best to answer all these questions and more in this lesson.

Related:

You may have heard of lambdas before. Perhaps you've used them in other languages. Despite the fancy name, a lambda is just a function... peculiarly... without a name. They're anonymous, little functional spies sneaking into the rest of your code. Lambdas in Ruby are also objects, jus...

At some point every apprentice is tempted to look for a quick escape from a self-painted corner. The apprentice sees the trap of her own making at the bottom of many nested methods or loops. "I know!" she thinks. "I'll jump out with an exception!" But therein lies danger: exceptions a...