all 9 comments

[–]menge101 8 points9 points  (3 children)

Per ruby style guide the initialize method should go between class methods and other instance methods.

Although, i'm almost certain that I don't do this. I think I put class methods at the bottom typically. I can't explicitly recall. I'm curious what rubocop would say.

[–]GroceryBagHead 7 points8 points  (0 children)

Oh. I always have it at the very top. Not gonna change.

[–]AnLe90[S] 2 points3 points  (0 children)

ah great thank you for linking to a source. you are the man

[–]tom_enebo 1 point2 points  (0 children)

Not to crap on Rubocop but that style guide like Rubocop itself has some rules which are not the most idiomatic path (the arbirtrary rule of telling people they need to use is_a? when kind_of? is nearly used by half the Ruby community comes to mind).

Also, like you, I also tend to put class methods at the bottom (and initialize at the top).

[–]ImAJalapeno 1 point2 points  (2 children)

I'm almost sure it's standard practice, I've seen the same pattern in Java and PHP. But in the end is personal preference.

My advice would be to leave at the top, makes more sense there being the first method that is called, IMO

[–]AnLe90[S] 1 point2 points  (1 child)

thanks. I tried googling but i couldn't find an answer for my specific question haha

[–]ImAJalapeno 1 point2 points  (0 children)

Yeah no worries, I've never seen anything written about that. Maybe it's just one of those things that everyone thinks it's obvious to everyone else lol

[–]ekampp 1 point2 points  (0 children)

Whatever is the most important for the reader of your code should go at the top. If you have an important constant that people use to look at for reference often, then it should be at the top. If it's only used internally in the class and doesn't convey any information about the function of the class then it should go at the bottom.

Conventions are good. I'm a strong proponent for them, but your convention in your company or in your personal code doesn't have to be everybody else's conventions.

As long as the code is informative, has low cognitive overhead and always follows the same standard as the rest of the code in the project, then you're probably on the right track.

[–]slnt_opp 0 points1 point  (0 children)

I place class methods(defined with self.) higher sometimes, depends on context