Can I tell or hint to RubyMine what type a local or instance variable is?
It appears this is forthcoming, based on a recent comment posted to the issue tracker referenced by Matt Connolly: http://youtrack.jetbrains.com/issue/RUBY-9142#comment=27-787975
"local variables can be annotated with or without variable name:"
# @type [String]my_var = magic_method# @type my_var [String]my_var = magic_method# @type [String] my_varmy_var = magic_method# @type [String] my_var And some documentation is allowedmy_var = magic_method
"Also multi-assignments are supported:"
# @type my_var [String] The first part# @type other_var [Range] The second partmy_var, other_var = magic_method
"But in the case of a multi-assignment the form without var name would not work (this is arguable, but I incline to that it may lead to some errors)
Also block parameters can be annotated:"
method_with_block do # @type [String] param1 # @type [Range] param2 | param1, param2 | # some code...end
"The thing to note is that type annotations are to be placed after do or { and before block parameters list, to help avoiding probable ambiguity. In the case of one-liners it looks cumbersome, but I am not sure they are to be heavily annotated. Anyway, any suggestions are very welcome."
It's not 100% answer for this particular question, but could point to other useful trick.
In tests I'm doing it this way to trick RubyMine (5.0.2)
user = users(:normal) || User.new
since with fixtures I'm sure that the users(:first) will return the object, and because of Use.new - IDE thinks it should be User instance.
It appears not. I'd recommend looking in the issue tracker for existing feature requests, and add make your voice heard there. For example:
http://youtrack.jetbrains.com/issue/RUBY-9142
Update
This feature is now shipping with RubyMine 7.0 (Tsubaki) EAP (138.1968) and higher (but note that Rubymine 7.0 is currently in EAP (i.e. beta) and there's always a chance this might not make it to the final distro.)