ClassMethods vs append_features/extend self

I

Intransition

Thoughts on this:

module Foo

def self.append_features(base)
base.extend self
end

def foo
# ...
end

end

I have done the above at times, as opposed to the alternative:

module Foo

def self.append_features(base)
base.extend ClassMethods
end

module ClassMethods
def foo
# ...
end
end

end

b/c I never liked having this non-descript module about --it feels
extraneous.

The downside of the former approach is that there is no way to ever
actually *include* the module's methods, but for the purposes of the
program that's almost certainly a YAGNI.

Any other downsides?
 
7

7stud --

Thomas Sawyer wrote in post #996028:
Thoughts on this:


1) I would use included() rather than append_features() because it's a
more descriptive name for the event you are trying to hook into.

2) The second form is more versatile because you can use the module to
store both regular methods and class methods that are to be included.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top