Sha256: cdc5f98e55fbcf91403c519b9d8d37149b8e465817c8959ceb7b81331f29e54a

Contents?: true

Size: 1.8 KB

Versions: 3

Compression:

Stored size: 1.8 KB

Contents

# every_day_irb defines some helper methods that might be useful in every-day irb usage

module EveryDayIrb
  VERSION = File.read( File.dirname(__FILE__) + '/../VERSION' ).chomp
end

# shows the contents of your current directory (more such commands available by FileUtils)
def ls(path='.')
  Dir[ File.join( path, '*' )].map{|filename| File.basename filename }
end
alias dir ls

# read file contents (also see ray for ruby source files ;) )
def cat(path)
  File.read path
end

# allows concise syntax like rq:mathn
def rq(lib)
  require lib.to_s
end

# load shortcut, not suited for non-rb
def ld(lib)
  load lib.to_s + '.rb'
end

# rerequire, not suited for non-rb, please note: can have non-intended side effects in rare cases
def rerequire(lib)
  $".dup.each{ |path|
    if path =~ %r</#{lib}\.rb$>
      $".delete path.to_s
      require path.to_s
    end
  }
  require lib.to_s
  true
end
alias rrq rerequire

# restart irb
def reset!
  # remember history...
  reset_irb = proc{ exec$0 } 
  if defined?(Ripl) && Ripl.respond_to?(:started?) && Ripl.started?
    Ripl.shell.write_history if Ripl.shell.respond_to? :write_history
    reset_irb.call
  else
    at_exit(&reset_irb)
    exit
  end
end

# just clear the screen
def clear
  system 'clear'
end

# returns the last lines, needed for some copy_ methods
def session_history(number_of_lines = nil)
  if !number_of_lines
    if defined?(Ripl) && Ripl.respond_to?(:started?) && Ripl.started?
      number_of_lines = Ripl.shell.line
    else
      number_of_lines = context.instance_variable_get(:@line_no)
    end
  end
  Readline::HISTORY.entries[-number_of_lines...-1]*"\n"
end

# load debugger, inspired by rdp
def dbg
  begin
    require 'ruby-debug'
    debugger
  rescue LoadError => err
    throw "Sorry, unable to load ruby-debug gem for debugger: #{err}"
  end
end

# J-_-L

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
every_day_irb-1.2.2 lib/every_day_irb.rb
every_day_irb-1.2.1 lib/every_day_irb.rb
every_day_irb-1.2.0 lib/every_day_irb.rb