When emerge --info is called, it traverses all installed packages and searches for some signals from ebuilds. If there is, it will show those ebuilds' version. The signal could be a variable set in the ebuilds (EMERGE_INFO=1 maybe). Even better, if ebuilds has a special function (presumely pkg_info), then emerge --info will call that function and the function will provide more necessary info. Traversing all installed packages may be overkill. If "emerge --info" accepts a package as argument, then we can limit the search range.
Motivation / Use cases?
When there is a ruby-related bug, I usually have to ask dev-ruby/rubygems version. Other teams may need additional information like this.
Well, if you just need the version of a package then profiles/info_pkgs should do it already, though I guess we'd need to make it a bit more intelligent to not display packages that aren't installed.
Yes it could be. However I would expect a way for ebuilds to collect more info, not just version, from user system. I believe I encountered a case like that but I don't remember it.
Well, I'd rather not have random ebuilds inject random stuff into emerge --info. Keep in mind that emerge --info is just a general overview, not a complete system analysis tool, so if you need more information for certain groups of bugs a special tool to collect that information is IMO the way to go (that's what AFAIK the perl team has done)