Irb: Unterschied zwischen den Versionen

Aus C3D2
Zur Navigation springen Zur Suche springen
(+Kategorie)
 
(4 dazwischenliegende Versionen von 3 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
[[Kategorie:Ruby]]
[[Kategorie:Wissen]][[Kategorie:Ruby]]
 
Den folgenden Code einfach in die ~/.irbrc tun und schon steht die besschriebene Funktionalität zur Verfügung.
 
=History=
=History=
<pre>
<pre>
Zeile 17: Zeile 20:
         histfile if $DEBUG || $VERBOSE
         histfile if $DEBUG || $VERBOSE
     end
     end
     Kernel::at_exit {
     Kernel::at_exit {
       lines = Readline::HISTORY.to_a.reverse.uniq.reverse
       lines = Readline::HISTORY.to_a.reverse.uniq.reverse
       lines = lines[ -MAXHISTSIZE, MAXHISTSIZE ] if lines.nitems > MAXHISTSIZE
       lines = lines[ -MAXHISTSIZE, MAXHISTSIZE ] if lines.nitems > MAXHISTSIZE
       $stderr.puts "Saving %d history lines to %s." %
       $stderr.puts "Saving %d history lines to %s." %
         [ lines.length, histfile ] if $VERBOSE || $DEBUG
         [ lines.length, histfile ] if $VERBOSE || $DEBUG
       File::open( histfile, File::WRONLY|File::CREAT|File::TRUNC ) {|ofh|
       File::open( histfile, File::WRONLY|File::CREAT|File::TRUNC ) {|ofh|
Zeile 31: Zeile 32:
end
end
</pre>
</pre>
=ri in irb=
=ri in irb=
<pre>
<pre>
Zeile 37: Zeile 37:
   puts `ri #{arg}`
   puts `ri #{arg}`
end
end
class Module
class Module
   def ri(meth=nil)
   def ri(meth=nil)
Zeile 52: Zeile 51:
end
end
</pre>
</pre>
 
=Tab completion und Einrückung=
=Tab completion=
<pre>
<pre>
require 'irb/completion'
IRB.conf[:AUTO_INDENT] = true
ARGV.concat [ "--readline", "--prompt-mode", "simple" ]
IRB.conf[:USE_READLINE] = true
IRB.conf[:LOAD_MODULES] ||= []
IRB.conf[:LOAD_MODULES] |= ['irb/completion']  
</pre>
</pre>
Alternative: [http://www.rubyinside.com/wirble-tab-completion-and-syntax-coloring-for-irb-336.html Wirble]
{{Rübÿ Spëëd Mëtäl Cödïng}}

Aktuelle Version vom 17. Juli 2008, 09:17 Uhr


Den folgenden Code einfach in die ~/.irbrc tun und schon steht die besschriebene Funktionalität zur Verfügung.

History

HISTFILE = "~/.irb.hist"
MAXHISTSIZE = 10000
 
begin
  if defined? Readline::HISTORY
    histfile = File::expand_path( HISTFILE )
    if File::exists?( histfile )
      lines = IO::readlines( histfile ).collect {|line| line.chomp}
      puts "Read %d saved history commands from %s." %
        [ lines.nitems, histfile ] if $DEBUG || $VERBOSE
      Readline::HISTORY.push( *lines )
    else
      puts "History file '%s' was empty or non-existant." %
        histfile if $DEBUG || $VERBOSE
    end
    Kernel::at_exit {
      lines = Readline::HISTORY.to_a.reverse.uniq.reverse
      lines = lines[ -MAXHISTSIZE, MAXHISTSIZE ] if lines.nitems > MAXHISTSIZE
      $stderr.puts "Saving %d history lines to %s." %
        [ lines.length, histfile ] if $VERBOSE || $DEBUG
      File::open( histfile, File::WRONLY|File::CREAT|File::TRUNC ) {|ofh|
        lines.each {|line| ofh.puts line }
      }
    }
  end
end

ri in irb

def ri arg
   puts `ri #{arg}`
end
class Module
   def ri(meth=nil)
     if meth
       if instance_methods(false).include? meth.to_s
         puts `ri #{self}##{meth}`
       else
         super
       end
     else
       puts `ri #{self}`
     end
   end
end

Tab completion und Einrückung

IRB.conf[:AUTO_INDENT] = true
IRB.conf[:USE_READLINE] = true
IRB.conf[:LOAD_MODULES] ||= []
IRB.conf[:LOAD_MODULES] |= ['irb/completion'] 

Alternative: Wirble


Rübÿ Spëëd Mëtäl Cödïng
Coders: Astro | Conny | Sven