I am seeing a lot of different preferences around the following:
class Foo
VAR = "Some string".freeze
# or
def self.var
"Some String"
end
end
both can be accessed the same way:
Foo::VAR
#=> "Some String"
Foo::var
#=> "Some String"
but you can also do Foo.var
to get the same string if it was a method. defining it as a variable feels like you break the power of encapsulation that OO gives us. I see however a lot of strings/magic numbers being stored in variables inside class's, this seems like a more common practice.
I am not sure which is right.
EDIT Sorry, my question is a little confusing. I wanted to find out if it's better to store strings in methods vs storing them in variables for a class. Me explaining how to call the methods confused the question.