Commit 44b6bff
committed
Narrow Resolv::DNS resource methods by typeclass via bounded generic
`Resolv::DNS#getresource` / `#getresources` / `#each_resource` /
`#extract_resources` accept a typeclass argument (e.g.
`Resolv::DNS::Resource::IN::MX`) that fully determines the returned
resource subclass. The signatures returned the upper bound
`Resolv::DNS::Resource`, dropping that information; callers using
subclass-specific methods like `MX#exchange` then need a downcast.
Use a bounded type parameter (`[T < Resolv::DNS::Resource]`) so the
return / block parameter tracks the typeclass:
def getresources: [T < Resolv::DNS::Resource] (dns_name, singleton(T)) -> Array[T]
| (dns_name, singleton(Resolv::DNS::Resource::ANY)) -> Array[Resolv::DNS::Resource]
`Resolv::DNS::Resource::ANY` does not inherit from `Resource` (it sits
parallel under `Query`), so the wide overload is kept alongside as the
fallback for `ANY` queries.
`fetch_resource` also takes a typeclass argument but does not return or
yield a `Resource`, so it is left as-is.1 parent fcc1685 commit 44b6bff
1 file changed
Lines changed: 8 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
221 | | - | |
| 221 | + | |
| 222 | + | |
222 | 223 | | |
223 | | - | |
| 224 | + | |
| 225 | + | |
224 | 226 | | |
225 | 227 | | |
226 | 228 | | |
| |||
299 | 301 | | |
300 | 302 | | |
301 | 303 | | |
302 | | - | |
| 304 | + | |
| 305 | + | |
303 | 306 | | |
304 | 307 | | |
305 | 308 | | |
| |||
308 | 311 | | |
309 | 312 | | |
310 | 313 | | |
311 | | - | |
| 314 | + | |
| 315 | + | |
312 | 316 | | |
313 | 317 | | |
314 | 318 | | |
| |||
0 commit comments