Well, I thought this was easy, but for some reason it won’t work…
Here is what I want to do:
I am working on an API to a large database. The basic mapping is done,
but I want to implement some convenience methods that take information
for one object and does some calculations with it. The result should be
accessible as attribute.
So in a simple example:
We have an object that has a start and a stop attribute, i.e. columns in
the table. Now I want to know the distance, but directly via an readable
@distance = self.stop-self.start
However, if I use my_object.distance, it returns nil…
What am I doing wrong?
P.S. I also tried
def initialize(distance) - but figured that only makes sense if I
specifically create a new object, not if the attribute is created from
within the class. Didn’t work either, anyway.