Giter Site home page Giter Site logo

ripl's Introduction

Description

Ruby Interactive Print Loop - A light, modular alternative to irb

Install

Install the gem with:

sudo gem install ripl

Features

  • Similar to irb

    • Reads ~/.irbrc on startup

    • Appends to ~/.irb_history on exit

    • Autocompletion (from bond)

    • _ for last result

    • Type ‘exit’ or Ctrl-D to exit

    • 6 common commandline options: -f, -r, -I, -d, -h, -v

    • IRB.conf -> Ripl.config

  • Enhancements over irb

    • ~200 lines vs irb’s 5000+ lines

    • Easily extendable with plugins

    • Tests!

    • Customizable completion and completion of method arguments (from bond)

    • Easy to create custom shells for gems and apps i.e. Ripl.start

    • Easy to create and invoke ripl subcommands

    • ~/.irbrc errors caught

  • Different from irb

    • No multi-line evaluation by default (there is a plugin. See Available Plugins below).

    • No irb subsessions or workspaces

    • No IRB.conf features i.e. preconfigured prompts and auto indent

Note: Irb features not in ripl can be implemented as plugins.

Philosophy

ripl is a light, flexible repl(shell) meant to lay the foundation for customizable ruby shells. It provides an environment for plugins to share and reuse best practices for shells. ripl can be easily customized for gems, applications and is even usable on the web (see nirvana).

Usage

$ ripl
>> ...

Plugins

A ripl plugin is a module that is included into Ripl::Shell or Ripl::Runner. Being simply modules, they can be packaged as gems and reused across shells as needed. ripl highly encourages plugins by loading them as early as possible and allowing them to extend most of ripl’s functionality.

As an example plugin, let’s color error messages red:

# Place in ~/.riplrc
module Ripl
  module RedError
    def format_error(error)
      "\e[31m#{super}\e[m"
    end
  end
end
Ripl::Shell.send :include, Ripl::RedError

Note this plugin extends format_error() by invoking the original format_error() with super. This is possible for any method that is available for extension by plugins. To see methods are available for extension, see Ripl::Shell::API and Ripl::Runner::API.

If we want to add a config for this plugin, we can simply add a key to Ripl.config that matches the underscored version of the plugin name i.e. Ripl.config.

For available plugins, see Available Plugins below.

Create Custom Shells

Creating and starting a custom shell is as simple as:

require 'ripl'
# Define plugins, load files, etc...
Ripl.start

Ripl.start takes options to customize your shell. For example if you wanted to start on a specific binding:

Ripl.start :binding => my_desired_binding

Create Commands

If you want to invoke your custom shell with ripl, make it a ripl command. To create one, create an executable in the format ripl-<command> and make sure it’s in your shell’s $PATH. For example, the file ‘ripl-my_gem’ would be invoked with ‘ripl my_gem`. Note that with your command you can take arguments and parse your options as you please. For an example command, see ripl-rails.

Customize ripl

Since ripl is highly customizable, it loads ~/.riplrc before it does anything. This ruby file should require and/or define plugins. Any ripl configurations via Ripl.config should also be done here. For an example riplrc, see mine.

Available Plugins

Credits

  • janlelis for bug fix and tweaks

irb alternatives

Some other irb alternatives to check out:

  • ir: nice and light

  • irb2: yehuda katz’s partial attempt at rewriting irb

  • dietrb: mac and ruby 1.9 specific

ripl's People

Contributors

cldwalker avatar janlelis avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.