sr

sr is a simple, tiny, hackable REPL for Ruby.

Usage

Simply call sr to use sr as a Ruby REPL like irb or pry:

$ sr

sr can also be used to include a REPL in your own code (for debugging purposes, for example) by requiring 'sr' and calling SR.repl:

require 'sr'

class Test
  def initialize
    SR.repl
  end
end

You may also pass any object to the SR.repl method to have sr begin in the context of that object instead of the default (the top level binding):

class Test
  def initialize
    SR.repl(self)
  end
end

Within the REPL itself, you can manipulate the current context via the methods SR.bind, SR.unbind, and SR.reset_binding:

$ sr
== main:
>> SR.bind Object.new
-> #<Binding:0x81338ed0>
== #<Object:0x81338f34>:
>> SR.unbind
-> #<Binding:0x8124dc78>
== main:
>> 

SR.bind sets the current context to the given object and pushes the previous context onto the context stack; SR.unbind retrieves the last object from the stack and sets the context to it. SR.reset_binding may be used without arguments at any time to completely clear the context stack and reset the binding to the default (usually the top level binding).

When given an argument, however, SR.reset_binding clears the context stack and resets the default binding to the given object.

Configuration

sr looks for its configuration in the 'sr/config.rb' file within $XDG_CONFIG_DIRS and $XDG_CONFIG_HOME. By default, these files would be '/etc/xdg/sr/config.rb' for system-wide configuration and '~/.config/sr/config.rb' for user-specific configuration. These files are simply Ruby files which are loaded into sr via require.

License

sr is free and unencumbered software released into the public domain.