New Methods in Ruby 2.2

In that particular example it’s serving the same purpose as self. The difference is that a binding can be passed around.

class A
  def get_binding
    binding
  end
end

> a = A.new
# => #<A:0x007fe9b44cd880>
> b = a.get_binding
# => #<Binding:0x007fe9b44fcfe0>
> b.receiver
# => #<A:0x007fe9b44cd880>

Bindings are a window into a particular scope. Now it’s easier to find where that scope came from. Does that help clarify it?

1 Like