Love U Ruby wrote in post #1108785:
> I was trying to list the all the class names having the pattern `stri`
> with the below:
>
> p ObjectSpace.each_object(Class).to_a.grep(/(stri)/i) #=> []
>
> But not getting the output. So can anyone help me on the same?

ObjectSpace.each_object(Class) is returning an Enumerator of Class 
object. Then you are shoving a bunch of class objects into an array and 
then expecting grep to know what to do with them.

If you were to run:

irb(main):> ObjectSpace.each_object(Class) { |x| p x.class }
Class
Class
Class
...
...
...
=> 383

Calling to_a on that Enumerator you get an array of Class objects, NOT 
strings. When sending the grep message to an Array return any elements 
where Pattern === element.

What you probably want instead is an array of class names as strings not 
Class objects. Then grep should work just fine.

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to