0

Compared to the code completion I am familiar with from C# development, I find the code completion offered by RubyMine surprisingly incomplete.

  1. When I write a class with some methods and I want to call them from another class,
    why am I getting a code-completion list that is like "a mile" long, but with no relevant method-suggestions in it?
    ( Or is this a bug/feature in my RubyMine?! )

  2. Some classes like ActionMailer magically generate methods like the "deliver_*" methods ( see this example )... As I don't see them in code completion how am I supposed to know they even exist?
    ( Unfortunately I also get an error at the moment, that deliver_contact method does not exist... As I completely copied from the example am asking myself now wheter this feature still exists 8[ )

Are they any ways to fix these issues?

Chris Johnsen
  • 214,407
  • 26
  • 209
  • 186
David
  • 2,551
  • 3
  • 34
  • 62

3 Answers3

5

It's not that Ruby wasn't "designed" to be used with code completion, it's that behavior can be added in a variety of ways, including during program execution. This makes code completion hard. RubyMine does a good job, but only for obvious or known functionality, when an object's type is known.

http://apidock.com provides reference material for Ruby, Rails, and RSpec. Playing around in irb/pry can help a lot. You can always get methods on a class/instance by eval-ing foo.methods in a REPL (although I almost always foo.methods.sort).

That list can be filtered if you "sort of" know what you're looking for with find/grep, e.g.

> "foo".class.instance_methods(false).sort.grep /each/
=> [:each_byte, :each_char, :each_codepoint, :each_line]

In the Rails environment, running rails console (I prefer using pry for the console, YMMV) gives you access to your environment, including exposing a lot of the dynamic methods. Note that some methods do not exist until they are called for the first time (notably those of the find_by_foo_and_bar variety) so some functionality may still be hidden.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • The truth is though that most coders on the Ruby/Rails core teams use just text editors. – Jakub Hampl Oct 22 '11 at 19:18
  • 5
    @JakubHampl So? Doesn't mean it's the most efficient thing to do (it isn't), or that everyone does, or that you can't use both (I use both). – Dave Newton Oct 22 '11 at 19:20
  • 1
    Dave I always enjoy your postings and love this one. Yes I use multiple OS's (MAC/Win/U) and many editors and IDE's. – Michael Durrant Oct 25 '11 at 23:10
  • @MichaelDurrant Thanks; that's very kind. Yeah, the whole IDE v. text editor thing confuses me--right tool for the job, and they all have their places, strengths, and weaknesses! – Dave Newton Oct 25 '11 at 23:12
0

The main reason you get these problems is that Ruby(onRails) was never designed to be used with code completion. Most Rubyist code in a text editor and are very happy that they don't need code completion.

In the current version of Rails the deliver_* methods are deprecated in favour of MyClass.contact.deliver style.

Jakub Hampl
  • 39,863
  • 10
  • 77
  • 106
  • 1
    ok, thanks for the hint but it doesn't really answer my question.. how do you "know" of the methods of a class.. or do you read it up on the internet? ^^ – David Oct 22 '11 at 18:52
  • 1
    You'll find yourself reading source a lot, or docs when available. Style varies between programmers of course, but many Ruby libraries rely heavily on meta-programming and dynamically written methods. Such techniques simply don't lend themselves well to auto-completion. – numbers1311407 Oct 22 '11 at 18:57
  • @David Dave answered that pretty well. After you have some experience with Rails you often just guess :) apidock is a great site, I use it all the time. – Jakub Hampl Oct 22 '11 at 19:16
0

All the method that follow the following structure: deliver_* are using the meta programming philosophy.

Here's a very simple example: Ruby: define_method vs. def

You will find that a lot of stuff in rails has to do with method missing and the meta programming philosophy.

Community
  • 1
  • 1
Pier-Olivier Thibault
  • 3,907
  • 2
  • 33
  • 33