module Brice::Shortcuts::ObjectShortcuts
Public Instance Methods
aorta(obj = self, editor = nil)
click to toggle source
Cf. <rubyforge.org/snippet/detail.php?type=snippet&id=22>
# File lib/brice/shortcuts.rb 130 def aorta(obj = self, editor = nil) 131 tempfile = Tempfile.new('aorta') 132 YAML.dump(obj, tempfile) 133 tempfile.close 134 135 if editor ||= File.which_command(EDITORS) 136 system(editor, path = tempfile.path) 137 return obj unless File.exists?(path) 138 else 139 warn 'No suitable editor found. Please specify.' 140 return obj 141 end 142 143 content = YAML.load_file(path) 144 tempfile.unlink 145 content 146 end
cgrep(needle)
click to toggle source
# File lib/brice/shortcuts.rb 95 def cgrep(needle) 96 needle = %r{#{Regexp.escape(needle)}}i unless needle.is_a?(Regexp) 97 klass = is_a?(Class) ? self : self.class 98 res = [] 99 100 ObjectSpace.each_object(Class) { |obj| 101 next unless obj <= klass 102 103 name = obj.name 104 next unless name =~ needle 105 106 res.push(name.empty? ? obj.inspect : name) 107 } 108 109 res 110 end
mgrep(needle)
click to toggle source
# File lib/brice/shortcuts.rb 112 def mgrep(needle) 113 methods.grep( 114 needle.is_a?(Regexp) ? needle : %r{#{Regexp.escape(needle)}}i 115 ) 116 end
po(obj = self)
click to toggle source
Print object methods, sorted by name. (excluding methods that exist in the class Object)
# File lib/brice/shortcuts.rb 120 def po(obj = self) 121 obj.methods.sort - Object.methods 122 end
poc(obj = self)
click to toggle source
Print object constants, sorted by name.
# File lib/brice/shortcuts.rb 125 def poc(obj = self) 126 obj.constants.sort if obj.respond_to?(:constants) 127 end