Skip to content

Commit

Permalink
Disallow extend self inside of a class.
Browse files Browse the repository at this point in the history
Closes gh-202
  • Loading branch information
lsegal committed Nov 11, 2010
1 parent 9717677 commit 2a5a989
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/yard/handlers/ruby/extend_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ def scope; :class end

def process_mixin(mixin)
if mixin == s(:var_ref, s(:kw, "self"))
if namespace.is_a?(ClassObject)
raise UndocumentableError, "extend(self) statement on class"
end
namespace.mixins(scope) << namespace
else
super
Expand Down
3 changes: 3 additions & 0 deletions lib/yard/handlers/ruby/legacy/extend_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ def scope; :class end

def process_mixin(mixin)
if mixin == "self"
if namespace.is_a?(ClassObject)
raise UndocumentableError, "extend(self) statement on class"
end
namespace.mixins(scope) << namespace
else
super
Expand Down
4 changes: 4 additions & 0 deletions spec/handlers/extend_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
it "should extend module with correct namespace" do
Registry.at('Q::R::S').class_mixins.first.path.should == 'A'
end

it "should not allow extending self if object is a class" do
undoc_error "class Foo; extend self; end"
end
end

0 comments on commit 2a5a989

Please sign in to comment.