Module: Kernel
- Defined in:
- lib/yaih/kernel.rb
Instance Method Summary collapse
- #decorate_h(n) ⇒ Object
- #h(n = 10) ⇒ Object
- #h!(start, stop = nil) ⇒ Object
- #hgrep(word) ⇒ Object
- #history_a(n = Readline::HISTORY.size) ⇒ Object
Instance Method Details
#decorate_h(n) ⇒ Object
8 9 10 11 |
# File 'lib/yaih/kernel.rb', line 8 def decorate_h(n) size=Readline::HISTORY.size ((size - n)..size-1).zip(history_a(n)).map {|e| e.join(" ")} end |
#h(n = 10) ⇒ Object
13 14 15 16 17 |
# File 'lib/yaih/kernel.rb', line 13 def h(n=10) entries = decorate_h(n) puts entries entries.size end |
#h!(start, stop = nil) ⇒ Object
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 code = history_a[start..stop] code.each_with_index { |e,i| irb_context.evaluate(e,i) } Readline::HISTORY.pop code.each { |l| Readline::HISTORY.push l } puts code end |
#hgrep(word) ⇒ Object
19 20 21 22 23 |
# File 'lib/yaih/kernel.rb', line 19 def hgrep(word) matched=decorate_h(Readline::HISTORY.size - 1).select {|h| h.match(word)} puts matched matched.size end |
#history_a(n = Readline::HISTORY.size) ⇒ Object
3 4 5 6 |
# File 'lib/yaih/kernel.rb', line 3 def history_a(n=Readline::HISTORY.size) size=Readline::HISTORY.size Readline::HISTORY.to_a[(size - n)..size-1] end |