module Brice::Shortcuts

Convenient shortcut methods.

Set config.shortcuts.opt = { object: false } to disable ObjectShortcuts, or config.shortcuts.opt = { ri: false } to disable ri shortcuts.

Public Instance Methods

init(opt = {}) click to toggle source
   # File lib/brice/shortcuts.rb
50 def init(opt = {})
51   init_object if Brice.opt(opt, :object)
52   init_ri     if Brice.opt(opt, :ri)
53 end
init_object() click to toggle source
   # File lib/brice/shortcuts.rb
55 def init_object
56   Object.send(:include, ObjectShortcuts)
57 end
init_ri() click to toggle source
   # File lib/brice/shortcuts.rb
59 def init_ri
60   Module.class_eval {
61     def ri(*args)
62       ri!('--no-pager', *args)
63     end
64 
65     def ri!(*args)
66       opts, args = args.partition { |arg| arg.to_s.start_with?('--') }
67 
68       args.empty? ? args << name : args.map! { |arg|
69         arg, method = arg.to_s, nil
70 
71         delim = [['#', :instance_method], ['::', :method]].find { |i, m|
72           match  = arg.sub!(/\A#{i}/, '')
73           method = begin; send(m, arg); rescue NameError; end
74 
75           break i if match || method
76         } or next arg
77 
78         "#{method && method.to_s[/\((\w+)\)/, 1] || name}#{delim}#{arg}"
79       }
80 
81       system('ri', *opts.concat(args))
82     end
83   }
84 
85   instance_eval {
86     def ri(*args);  Kernel.ri(*args);  end
87     def ri!(*args); Kernel.ri!(*args); end
88   }
89 end
ri(*args) click to toggle source
   # File lib/brice/shortcuts.rb
61 def ri(*args)
62   ri!('--no-pager', *args)
63 end
ri!(*args) click to toggle source
   # File lib/brice/shortcuts.rb
65 def ri!(*args)
66   opts, args = args.partition { |arg| arg.to_s.start_with?('--') }
67 
68   args.empty? ? args << name : args.map! { |arg|
69     arg, method = arg.to_s, nil
70 
71     delim = [['#', :instance_method], ['::', :method]].find { |i, m|
72       match  = arg.sub!(/\A#{i}/, '')
73       method = begin; send(m, arg); rescue NameError; end
74 
75       break i if match || method
76     } or next arg
77 
78     "#{method && method.to_s[/\((\w+)\)/, 1] || name}#{delim}#{arg}"
79   }
80 
81   system('ri', *opts.concat(args))
82 end