Class method vs constant in Ruby/Rails

ruby, ruby-on-rails

Solution

The latter is better. If it were a method, a new array and new strings will be created every time it is called, which is a waste of resource.

Problem

I was implementing a form that includes a hard-coded dropdown for a collection and I was wondering what would be the best solution, I know both ways exposed below work, still I did as follows: ``` class Example # Options for Example. self.options [ 'Yes', 'No', 'Not sure' ] end end ``` which is called by `Example.options`, but I know it is possible to do as follows as well: ``` class Example # Options for Example. OPTIONS = [ 'Yes', 'No', 'Not sure' ] end ``` that would be called with `Example::OPTIONS`. The question is, is any of these the good way or it just doesn't matter at all?

Original source

Related problems