Giter Club home page Giter Club logo

dietrb's Introduction

IRB on a diet, for MacRuby / Ruby 1.9

The goal is to have a small and cleaned up version of IRB. Trimmed down to only do the stuff I, and most people I know, actually use.

Trimming down the core code is done mainly by using Ripper, which comes with Ruby 1.9, instead of shipping it’s own parser etc.

There’s still lots to be done, but the ‘basic functionality’ as is now, should not grow too much more. For now my things to-do are .irbrc support, completion, and investigate what else people really really need. After that it’s time to polish.

Important notice

Since on Ruby 1.9 all latest gems are pushed onto the load path by default, installing the DietRB gem would break the existing IRB binary. Therefor, with the DietRB gem is installed, it will hijack the ‘irb’ bin file.

The original IRB will still work when you uninstall the DietRB gem, though.

Extensions

  • irb/ext/colorize.rb, adds support for colorizing the prompt and result. The code was based upon Wirble’s implementation, so your custom Wirble themes should still work.

    Configure it with:

    • IRB.formatter.color_scheme = scheme, where scheme can be: :dark_background, :light_background, or :fresh. Defaults to :dark_background.

    • IRB.formatter.colors returns the hash of current token-type to color mappings.

  • irb/ext/completion.rb, adds, as the name implies, autocompletion for constants, variables, methods, etc.

  • irb/ext/history.rb, stores/loads the history in and from the history file, which is located at ~/.irb_history.

    It provides the following API:

    • Kernel#history(N), or Kernel#h, will show N number of the most recent history entries. Defaults to 50.

    • Kernel#history!(entry_or_range), or Kernel#h!, will execute the specified history entry, or entries if a range is given.

    • Kernel#clear_history! will clear the history and the history file.

Differences

  • Dietrb will try to warn about syntax errors as soon as a line is entered and only reset the buffer to the previous line. This means that you don’t need to loose any previous work:

    IRB:

    irb(main):001:0> class A
    irb(main):002:1>   def foo
    irb(main):003:2>     } p :ok
    irb(main):004:1>   end
    SyntaxError: compile error
    (irb):3: syntax error, unexpected '}'
        } p :ok
         ^
    (irb):4: syntax error, unexpected $end, expecting kEND
    	from (irb):4
    	from :0
    irb(main):005:0> A.new.foo
    NameError: uninitialized constant A
    	from (irb):5
    	from :0

    Dietrb:

    irb(main):001:0> class A
    irb(main):002:1>   def foo
    irb(main):003:2>     } p :ok
    SyntaxError: compile error
    (irb):3: syntax error, unexpected '}'
    irb(main):004:2>     p :ok
    irb(main):005:2>   end
    irb(main):006:1> end
    => nil
    irb(main):007:0> A.new.foo
    :ok
    => :ok

Play

Normal usage:

irb(main):001:0> class A
irb(main):002:1>   def foo
irb(main):003:2>     :ok
irb(main):004:2>   end
irb(main):005:1> end
=> nil
irb(main):006:0> irb A.new
irb(#<#<Class:…>::A:…>):001:0> foo
=> :ok
irb(#<#<Class:…>::A:…>):002:0> quit
=> nil
irb(main):007:0> quit

dietrb's People

Contributors

alloy avatar ferrous26 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.