[rspec-users] [rails] An authorization question
phlip2005 at gmail.com
Mon Mar 2 14:57:38 EST 2009
James Byrne wrote:
> Is this a semantic confusion on my part? Should I consider that what I
> do with x.exists? is tell the object to answer a question?
Now lets upgrade the variable x. Sometimes it points to a thing that exists, and
sometimes it points to a stub object whose only job is to return 'false' from
exists?, and do nothing inside important_method():
Now you can take out the if!
We are no longer asking x if it exists. We are telling it what to do, and
letting it decide how to do it. That is the heart of OO programming.
(There is still an 'if', somewhere - the one that populates x. But - hopefully -
it's only in one place.)
More information about the rspec-users