On Mon, May 13, 2013 at 7:19 AM, Love U Ruby <[email protected]> wrote:
> ObjectSpace.each_object(Class).to_a.grep(/(stri)/i)
>
ObjectSpace.each_object(Class).select { |x| x.to_s =~ /stri/i }
=> [String, RubyToken::TkDXSTRING, RubyToken::TkDSTRING,
RubyToken::TkXSTRING, RubyToken::TkSTRING]
(Hello from Ruby 2.0)
Other solutions give you the stringified class name. The above gives you
the class object, in case you want to do something with it beside fettle
its characters.
Nitpick: the () aren't necessary in that regex; they're only needed if
you're capturing part of the output. E.g.,
ObjectSpace.each_object(Class).map { |x| x.to_s =~ /(.*)::.*stri/i and $1
}.compact.uniq
=> ["RubyToken"]
ObjectSpace.each_object(Class).to_a.map(&:to_s).grep(/(.*)::.*stri/i) { |_|
$1 }.uniq
=> ["RubyToken"]
Paul
--
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.