Skip to content

Questions: How can we define a non-generic class that extends from a generic class? #1170

@nanachi-code

Description

@nanachi-code

I know we can define a class as generic using @generic tag, but I want to implement something like this:

# @generic T
class LinkedList
  # @yieldparam element [generic<T>]
  # @return [void]
  def each
  end
end

class Face < LinkedList # LinkedList<Edge>
  # I don't want to rewrite every generic methods like this:
  # @yieldparam element [Edge]
  # @return [void]
  def each
  end
end

face = Face.new
face.each { |e| e }
#               ^ should be Edge

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions