Module: Kernel

Defined in:
lib/yaih/kernel.rb

Overview

Adding methods to Kernel module makes possible to use them in irb.

Instance Method Summary collapse

Instance Method Details

#h(n = 10) ⇒ Fixnum

Prints the latest n lines from IRB history. It decorates each line with the correspondent command number.

Returns:

  • (Fixnum)

    number of printed lines.



7
8
9
10
11
# File 'lib/yaih/kernel.rb', line 7

def h(n=10)
    entries = Yaih::Core.decorate(n)
    puts entries
    entries.size
end

#h!(start, stop = nil) ⇒ nil

It takes the range of lines to execute, evals the lines and prints them.

Returns:

  • (nil)


25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/yaih/kernel.rb', line 25

def h!(start, stop=nil)
    stop=start unless stop
    lines = Yaih::Core.entries[start..stop]
    lines.each_with_index { |e,i|
        irb_context.evaluate(e,i)
    }
    Readline::HISTORY.pop
    lines.each { |l|
        Readline::HISTORY.push l
    }
    puts lines
end

#hgrep(word) ⇒ Fixnum

TODO:

Consider to highlight matched part.

It greps history and prints matched lines.

Returns:

  • (Fixnum)

    number of printed lines.



16
17
18
19
20
# File 'lib/yaih/kernel.rb', line 16

def hgrep(word)
    matched=Yaih::Core.decorate(Readline::HISTORY.size - 1).select {|h| h.match(word)}
    puts matched
    matched.size
end