Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support "extend self" for defining class methods #202

Closed
rspeicher opened this issue Nov 11, 2010 · 4 comments
Closed

Support "extend self" for defining class methods #202

rspeicher opened this issue Nov 11, 2010 · 4 comments

Comments

@rspeicher
Copy link

Currently the following syntax will cause Yard to list all defined methods as instance methods, rather than the class methods they actually are.

class Foo
  extend self
  
  def bar()
    # ...
  end
  
  def baz()
    # ...
  end
end

If possible, it'd be nice to support this method of doing things in addition to class << self and def self.bar.

Thanks!

@lsegal
Copy link
Owner

lsegal commented Nov 11, 2010

Well, they are both. Just because the instance methods are mixed into the class level, does not mean they stop being instance methods. Specifically, extend self is not the same as saying class << self or def self.bar. In the former case, a user can still do include Foo in their class to pull those methods in. You cannot do that with the latter two syntaxes, and therefore this information is important to document to the user (especially since modules are meant to be mixed in). YARD should properly document the methods as instance methods (they are), and mention that the module is mixed in as at the class level of the module.

That said, there seems to be a bug with extend self in that it causes a stackerror when generating html on my setup. I will fix that and attach the fix to this ticket.

@lsegal
Copy link
Owner

lsegal commented Nov 11, 2010

Oops, that error is due to an invalid example:

class Foo

cannot "extend self", since it is not a module. Updating the example to

module Foo

stops the stack error. I've actually disabled "extend self" from functioning on classes, since this leads to inconsistent behaviour.

@lsegal
Copy link
Owner

lsegal commented Nov 11, 2010

Disallow extend self inside of a class.

Closed by 2a5a989

@rspeicher
Copy link
Author

Thanks for the info. And class Foo was just my mistake while writing the ticket in a hurry, it should have of course been a module.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants