Allow abstract methods to be implemented via `method_missing`
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
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ả
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
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Shopify/type_toolkit
-
good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Shopify/type_toolkit#4 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Shopify/type_toolkit#45 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
Shopify/type_toolkit#20 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
Shopify/type_toolkit#14 ·
-
good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 52/100
Shopify/type_toolkit#10 ·
Tất cả issue của Shopify/type_toolkit
Issue tương tự
-
user-reported
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Kong/developer.konghq.com#7316 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
TheOdinProject/curriculum#31408 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
notch8/utk_knapsack#148 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
Homebrew/homebrew-cask#288729 · 1 bình luận ·
-
Test `FileUtils.options_of` Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100