Module: DebugBar::Ext::Binding

Defined in:
lib/debug-bar/ext/binding.rb

Overview

Binding extensions that are decorated onto bindings passed into callbacks.

Constant Summary collapse

VARIABLE_PATTERN =

A regex for matching only valid local, instance, class, and global variables, as well as constatns.

/^(@{1,2}|\$)?([_a-zA-Z]\w*)$/

Instance Method Summary collapse

Instance Method Details

#[](var) ⇒ Object

Returns the value of the given variable symbol within the binding. Supports local, instance, class, or global variables, as well as constants.

Raises:

  • (NameError)


10
11
12
13
# File 'lib/debug-bar/ext/binding.rb', line 10

def [](var)
  raise NameError, "#{var.inspect} is not a valid variable name" unless var.to_s =~ VARIABLE_PATTERN
  return self.eval(var.to_s)
end