Allow abstract methods to be implemented via `method_missing`

Đang mở
#11 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
ruby
Lĩnh vực
tooling

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện ví dụ MyInterface của issue với interface!, phương thức trừu tượng demo và Parent#method_missing, sau đó theo dõi điều gì xảy ra khi Child include MyInterface. So sánh đường đi lúc chạy với và không có việc include. Được xem là hoàn tất khi một phương thức trừu tượng được method_missing xử lý có thể được gọi mà không gặp NotImplementedError ngoài dự kiến, trong khi các phương thức bị thiếu không liên quan vẫn hoạt động như đã trình bày.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

good first issue

In theory: this should be possible:

# typed: true

require "type_toolkit"

module MyInterface
  interface!
  
  #: -> void
  def demo; end
end

class Parent
  def method_missing(m, ...)
    return super unless m == :demo
    
    puts "#demo implemented via #method_missing"
  end
end

class Child < Parent
  # Commenting out this module inclusion makes call succeed
  include MyInterface
end

Child.new.demo

For comparison, Sorbet's static typechecker doesn't allow this, because it doesn't have any way to prove what is or isn't implemented by method_missing. Sorbet runtime raises an error, which can be a change in runtime behaviour (compared to what you would expect without it):

# typed: true

require "sorbet-runtime"

module MyInterface
  extend T::Sig
  extend T::Helpers
  
  interface!
  
  sig { abstract.void }
  def demo; end
end

class Parent
  def method_missing(m, ...)
    return super unless m == :demo
    
    puts "#demo implemented via #method_missing"
  end
end

class Child < Parent
  # Commenting out this module inclusion makes call succeed
  include MyInterface
end

Child.new.demo # (NotImplementedError)
# The method `demo` on MyInterface is declared as `abstract`. It does not have an implementation.
Ngôn ngữ chính
Ruby
Star
3
Fork
5
Merge trung bình
8 ngày 23 giờ
Pull request đã merge (30 ngày)
8

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Shopify/type_toolkit

Tất cả issue của Shopify/type_toolkit

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.