Permalink
Browse files

lib/brice/shortcuts.rb (cgrep): Use #class if not a Class; use #inspe…

…ct if name empty.
  • Loading branch information...
1 parent 5c015e3 commit f1fc759f4ee23c3fd847c8577554d5fa03a3429c @blackwinter committed Aug 11, 2011
Showing with 8 additions and 6 deletions.
  1. +8 −6 lib/brice/shortcuts.rb
View
14 lib/brice/shortcuts.rb
@@ -81,14 +81,16 @@ module ObjectShortcuts
def cgrep(needle)
needle = %r{#{Regexp.escape(needle)}}i unless needle.is_a?(Regexp)
-
+ klass = is_a?(Class) ? self : self.class
res = []
- ObjectSpace.each_object { |obj|
- if obj.is_a?(Class) && obj <= self
- name = obj.name
- res << name if name =~ needle
- end
+ ObjectSpace.each_object(Class) { |obj|
+ next unless obj <= klass
+
+ name = obj.name
+ next unless name =~ needle
+
+ res.push(name.empty? ? obj.inspect : name)
}
res

0 comments on commit f1fc759

Please sign in to comment.