Toxic Elephant

Don't bury it in your back yard!

Redefined Accessors

Posted by matijs 10/12/2010 at 09h29

If you’re going to do this:

<typo:code lang=“ruby”>
def foo= f
@foo = f + “ bar”
end
</typo:code>

Then don’t first do this:

<typo:code lang=“ruby”>
attr_accessor :foo
</typo:code>

But instead do this:

<typo:code lang=“ruby”>
attr_reader :foo
</typo:code>

That way, there won’t be “method redefined” warnings all over the place.

Let’s make this more general: Before you release your gem, make sure it
runs without warnings. They should stick out like a sore thumb when you run
your tests, anyway.

Thanks.

Tags no comments no trackbacks

Comments

Comments are disabled