full text searching for ri content
Check it out. Quick and dirty searching of ri content:
Updated using: http://blog.zenspider.com/archives/2006/08/new_and_improve.html
They added path independence and searching of gems and local installed ri/rdoc. Enjoy!
1 2 #!/usr/local/bin/ruby -w 3 4 require 'rdoc/ri/ri_paths' 5 require 'find' 6 require 'yaml' 7 8 search = ARGV.shift 9 10 puts "Searching for #{search}" 11 puts 12 13 dirs = RI::Paths::PATH 14 dirs.each do |dir| 15 Dir.chdir dir do 16 Find.find('.') do |path| 17 next unless test ?f, path 18 yaml = File.read path 19 if yaml =~ /#{search}/io then 20 full_name = $1 if yaml[/full_name: (.*)/] 21 puts "** FOUND IN: #{full_name}" 22 23 data = YAML.load yaml.gsub(/ \!.*/, '') 24 desc = data['comment'].map { |x| x.values }.flatten.join("\n").gsub(/"/, "'").gsub(/</, "<").gsub(/>/, ">").gsub(/&/, "&") 25 puts 26 puts desc 27 puts 28 end 29 end 30 end 31 end
Lets you do stuff like:
1 2 % ./risearch.rb duplicate 3 Searching for duplicate 4 [...] 5 ** FOUND IN: Array#uniq! 6 7 Removes duplicate elements from self. Returns nil if no changes are made (that is, no duplicates are found). 8 a = [ 'a', 'a', 'b', 'b', 'c' ] 9 a.uniq! #=> ['a', 'b', 'c'] 10 b = [ 'a', 'b', 'c' ] 11 b.uniq! #=> nil 12 13 ** FOUND IN: Array#| 14 15 Set Union---Returns a new array by joining this array with other_array, removing duplicates. 16 [ 'a', 'b', 'c' ] | [ 'c', 'd', 'a' ] 17 #=> [ 'a', 'b', 'c', 'd' ] 18 [...]
Posted by zenspider at August 15, 2006 04:16 PM | Bookmark This
Categories: Rails , Ruby , Toys