ClassMethods vs append_features/extend self

Discussion in 'Ruby' started by Intransition, May 1, 2011.

  1. Intransition

    Intransition Guest

    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?
    Intransition, May 1, 2011
    #1
    1. Advertising

  2. Intransition

    7stud -- Guest

    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.

    --
    Posted via http://www.ruby-forum.com/.
    7stud --, May 2, 2011
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ralf W. Grosse-Kunstleve
    Replies:
    16
    Views:
    561
    Lonnie Princehouse
    Jul 11, 2005
  2. Ralf W. Grosse-Kunstleve
    Replies:
    18
    Views:
    581
    Bengt Richter
    Jul 11, 2005
  3. Ralf W. Grosse-Kunstleve
    Replies:
    2
    Views:
    390
    Dan Sommers
    Jul 12, 2005
  4. falcon
    Replies:
    0
    Views:
    362
    falcon
    Jul 31, 2005
  5. Bart Kastermans
    Replies:
    6
    Views:
    386
    Bart Kastermans
    Jul 13, 2008
Loading...

Share This Page