Why are rails not object oriented?

For example, why date helpers are written like this:

time_ago_in_words(@from_time) 

Instead of this:

 @from_time.time_ago_in_words 

Is this a clear design mistake / inconsistency? Or is there any reason for this?

+4
source share
2 answers

Great question!

Most helpers are for selecting dates / times.

http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html

I assume that no matter who writes, he wants to use several utility methods and so adds time_ago_in_words and distance_of_time_in_words to his assistant using selects.

Since time_ago_in_words and distance_of_time_in_words are concentrated (i.e. you can localize it), the developer may feel that the helper is not a bad place for them.

+2
source

Helpers are methods of the viewer, not the object that they display. This makes sense in the sense of OO, because a view displays data in a specific format, so it is responsible for converting models to this format.

+5
source

All Articles