Skip to content

Commit

Permalink
Try dropping the singleton_class? redefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
dgutov committed Mar 27, 2024
1 parent 7bdda53 commit e9ff835
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 15 deletions.
8 changes: 0 additions & 8 deletions lib/robe/core_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ class Module
alias_method :__name__, :name
end

if method_defined?(:singleton_class?)
alias_method :__singleton_class__?, :singleton_class?
else
def __singleton_class__?
self != Class && ancestors.first != self
end
end

unless method_defined?(:__singleton_class__)
alias_method :__singleton_class__, :singleton_class
end
Expand Down
2 changes: 1 addition & 1 deletion lib/robe/sash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def find_method_owner(mod, inst, sym)

def method_spec(method)
owner, inst = method.owner, nil
if owner.__singleton_class__?
if owner.singleton_class?
# FIXME: Use https://docs.ruby-lang.org/en/3.2/Class.html#method-i-attached_object
name = owner.to_s[/Class:([A-Z][^\(> ]*)/, 1] # defined in an eigenclass
elsif name = name_cache[owner]
Expand Down
2 changes: 1 addition & 1 deletion lib/robe/sash/includes_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def self.maybe_scan

ObjectSpace.each_object(Module) do |cl|
next unless cl.respond_to?(:included_modules)
next if cl.__singleton_class__?
next if cl.singleton_class?
cl.included_modules.each { |mod| includers[mod] << [cl, true] }
sc = cl.__singleton_class__
sc.included_modules.each { |mod| includers[mod] << [cl, nil] }
Expand Down
6 changes: 2 additions & 4 deletions lib/robe/type_space.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ def scan_with(scanner)
unless instance
singleton_ancestors = obj.singleton_class.ancestors

if RUBY_VERSION >= "2.1.0"
# Ruby 2.1 includes all singletons in the ancestors chain
singleton_ancestors.reject!(&:__singleton_class__?)
end
# Ruby 2.1+ includes all singletons in the ancestors chain
singleton_ancestors.reject!(&:singleton_class?)

scanner.scan(singleton_ancestors, true, false)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/robe/visor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Visor
SearchError = Class.new(StandardError)

def each_object(*args)
ObjectSpace.each_object(*args).reject { |m| m.__singleton_class__? }
ObjectSpace.each_object(*args).reject { |m| m.singleton_class? }
end

# Returns descendants and (modules only) also includers.
Expand Down

0 comments on commit e9ff835

Please sign in to comment.