/pry-globs

pry-globs decrypts Ruby's global variables within a Pry session.

Primary LanguageRubyMIT LicenseMIT

Gem Version Build Status Test Coverage Code Climate

pry-globs

What is it?

Pry plugin that enables you to find out the meaning of preset global variables within a Pry session.

Why, o why?

Often enough I come across a global variable, or a rarely used constant, whose meaning is unknown to me. If you ever encountered one, you know that Ruby's internal global variables are anything but named friendly.

So, instead of "googling" them each time, I decided to place them all under my fingertips. And what place better then a Pry session!? 😎

Installation

As usual...

$ gem install pry-globs

Usage

Each global variable has its definition and explanation.

Definition is mostly concise general description, while explanation is usually accompanied by a code example.

In order to get a definition or a constant, just pass its name to a globs command:

>> globs $!
Definition:
The exception information message set by 'raise'.

If you want to get an explanation as well as a definition, pass it an -e option.

>> globs -e $!
Definition:
The exception information message set by 'raise'.

Explanation:
It contains the exception when it is raised but not yet handled.
In most cases it can be accessed within the 'rescue' clause.

Given the following code..
> begin
>   5 / 0
> rescue
>   p $! # => #<ZeroDivisionError: divided by 0>
> end

Or when raising exception manually..
> class MyError < StandardError
> end
>
> begin
>   raise MyError, "Raise it high."
> rescue MyError
>   p $!         # => #<MyError: Raise it high.>
>   p $!.message # => "Raise it high."
> end

Caveats

Unfortunately, it is not possible to fetch data for $' and $" because of the ArgumentError within Pry. Pry parses an opening quote as an opening string quote. This can't be solved withing pry-globs. Instead, Pry should be patched. I am of the opinion the fix isn't worth of someone's hour or two, or three, or...

Contributing

As you can imagine, the hardest part was to fill the YAML file with the data. Mainly because it involved nontrivial research time. With that said, it is possible you will bump in to a mistake here and there. If you: find one, wish to expand on the existing data, or add your own, feel free to do so. You will have my gratitude. 🙇

Although the application is a small one, test suite exists. In case you add code and decide to open a PR, write tests as well.

If you decide only to add documentation to YAML file you do not have to add tests.

License

The gem is available as open source under the terms of the MIT License.