$30 off During Our Annual Pro Sale. View Details »

Lightning Talk Pry

Lightning Talk Pry

Pry is a great alternative to IRB, with many features the latter doesn't have. This talk quickly reviews some of them.

Kevin Sołtysiak

February 04, 2014
Tweet

More Decks by Kevin Sołtysiak

Other Decks in Programming

Transcript

  1. PRY
    More than « IRB with colors »

    View Slide

  2. WHY?
    IRB works, right?

    View Slide

  3. Well…

    View Slide

  4. Syntax coloration?
    !
    Persistent history?
    !
    Paging results?

    View Slide

  5. PRY
    Has those *by default*
    !
    And more.

    View Slide

  6. Shell
    integration

    View Slide

  7. [1] pry(main)> .git status
    On branch master
    Your branch is up-to-date with
    'origin/master'.

    View Slide

  8. Dev-friendly

    View Slide

  9. [8] pry(main)> cd FileUtils

    [9] pry(FileUtils):1> ls
    constants:
    DryRun Entry_ LOW_METHODS LowMethods METHODS
    FileUtils.methods:
    cd compare_stream install mv …
    FileUtils#methods: mode_to_s
    instance variables: @fileutils_label @fileutils_output
    locals: _ __ _dir_ _ex_ _file_ _in_ _out_ _pry_

    View Slide

  10. [10] pry(FileUtils):1> cd []
    [11] pry(#):2> ls

    Enumerable#methods: [...]
    Array#methods: [...]

    self.methods: __pry__

    View Slide

  11. [3] pry(main)> show-doc String#gsub
    From: string.c (C Method):
    Owner: String
    Visibility: public
    Signature: gsub(*arg1)
    Number of lines: 34
    !
    Returns a copy of str with the all occurrences of
    pattern substituted for the second argument. [...]

    View Slide

  12. [10] pry(main)> show-source String#gsub
    From: string.c (C Method):
    Number of lines: 5
    !
    static VALUE
    rb_str_gsub(int argc, VALUE *argv, VALUE str)
    {
    return str_gsub(argc, argv, str, 0);
    }

    View Slide

  13. [5] pry(main)> raise ArgumentError, "Date expected,
    received Date"
    ArgumentError: Date expected, received Date
    from (pry):1:in `__pry__'

    !
    !
    !
    !
    !
    !
    !

    View Slide

  14. [5] pry(main)> raise ArgumentError, "Date expected,
    received Date"
    ArgumentError: Date expected, received Date
    from (pry):1:in `__pry__'

    [6] pry(main)> wtf?
    Exception: ArgumentError: Date expected, received Date
    --
    0: (pry):1:in `__pry__'
    1: /Users/ksol/.rbenv/versions/2.0.0-p247/lib/ruby/gems/
    2.0.0/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:328:in
    `eval’

    View Slide

  15. See/replay history inside a session
    !
    Special locals (last file opened, etc)
    !
    Open in $EDITOR
    !

    View Slide

  16. DEBUGGER

    View Slide

  17. binding.pry

    View Slide

  18. Plugins!
    !
    eg: pry-nav, pry-debugger, pry-stack_explorer
    !
    => next, step, finish, break, up, down, show-
    stack, …

    View Slide

  19. http://pryrepl.org

    View Slide

  20. Thanks!
    @ksol (twitter/SO/Github)

    View Slide