Skip to content

Commit

Permalink
better documentation for Class descendants
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-makarov committed Dec 26, 2018
1 parent a2c8caa commit 78b7a0c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions lib/xcake/core_ext/class.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
module Xcake
module CoreExtensions
# Returns all descendants of a class
# @example Including in a class
# Class.send(:include, Xcake::CoreExtensions::ClassDescendants) # done with send because of old ruby versions
#
def descendants
ObjectSpace.each_object(singleton_class).select { |klass| klass < self }
module ClassDescendants
# Returns all descendants of a class
#
def descendants
ObjectSpace.each_object(singleton_class).select { |klass| klass < self }
end
end
end
end
2 changes: 1 addition & 1 deletion lib/xcake/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Generator
include Dependency
include Plugin
include Visitor
Class.send(:include, CoreExtensions) # done with send because of old ruby versions
Class.send(:include, CoreExtensions::ClassDescendants) # done with send because of old ruby versions

attr_accessor :context

Expand Down
2 changes: 1 addition & 1 deletion spec/core_ext/class_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

class Parent
Class.send(:include, Xcake::CoreExtensions) # done with send because of old ruby versions
Class.send(:include, Xcake::CoreExtensions::ClassDescendants) # done with send because of old ruby versions
end

class Child < Parent
Expand Down

0 comments on commit 78b7a0c

Please sign in to comment.