Your SlideShare is downloading. ×
0
completion_proc and history
completion_proc and history
completion_proc and history
completion_proc and history
completion_proc and history
completion_proc and history
completion_proc and history
completion_proc and history
completion_proc and history
completion_proc and history
completion_proc and history
completion_proc and history
completion_proc and history
completion_proc and history
completion_proc and history
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

completion_proc and history

401

Published on

Published in: Technology, Education
1 Comment
2 Likes
Statistics
Notes
No Downloads
Views
Total Views
401
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
1
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. completion_procno6v (Nobuhiro IMAI) RubyKansai Sat, 21 Jul 2012
  • 2. require "readline" line edit (←→) history (↑↓) completion (Tab)01 14
  • 3. line edit Readline.readline("⚡ ") ⚡ ←→02 14
  • 4. history Readline.readline("⚡ ", true) ⚡ Readline::HISTORY.clear ⚡ Readline::HISTORY << "a" ⚡ Readline::HISTORY << "b" ⚡ ↑↓03 14
  • 5. completion Readline.completion_proc Readline.completion_proc = ->(word){%w[word1 word2 ...]}04 14
  • 6. demodemo
  • 7. memo of demo github.com/jugyo/earthquake github.com/no6v/ rubykansai55/blob/master/ completion_proc.rb06 14
  • 8. fat man in readline puts Readline. methods(false). grep(->m{/[=?]$/!~m}). sort_by(&:size). reverse # refs hp12c http://bit.ly/QnKcDS07 14
  • 9. GJ! Thanks!! http://bit.ly/QnFG8r08 14
  • 10. breakbreak
  • 11. Array-like object Readline::HISTORY.class # => Object Readline::HISTORY.singleton_methods(false) # => [:to_s, :[], :[]=, :<<, :push, :pop, :shift, :each, :length, :size, :empty?, :delete_at, :clear] Enumerable === Readline::HISTORY # => true10 14
  • 12. but, somethings lack... unshift(*obj) last first(n)/last(n) delete_if{|x| ... }11 14
  • 13. HISTORY.delete_if require "readline" class << Readline::HISTORY def delete_if(&block) return enum_for(__method__) unless block raise SecurityError if $SAFE == 4 i = 0 while (size > i) do break unless entry = self[i] if block.call(entry) delete_at(i) else i += 1 end end return self end end12 14
  • 14. hist_delete_if static VALUE hist_delete_if(VALUE self) { HIST_ENTRY *entry; int i = 0; RETURN_ENUMERATOR(self, 0, 0); rb_secure(4); while (history_length > i) { entry = history_get(history_get_offset_func(i)); if (entry == NULL) break; if (RTEST(rb_yield(rb_locale_str_new_cstr(entry->line)))) rb_remove_history(i); else i++; } return self; }13 14
  • 15. Thanks & Q?Thanks & Q?

×