Make LazyObject type-checkable.

This commit is contained in:
Markus Reiter 2021-01-13 09:22:06 +01:00
parent 9922ad382f
commit b1000952b1
3 changed files with 13 additions and 5 deletions

View File

@ -71,6 +71,10 @@ Layout/HeredocIndentation:
Metrics/ParameterLists: Metrics/ParameterLists:
CountKeywordArgs: false CountKeywordArgs: false
# Allow dashes in filenames.
Naming/FileName:
Regex: !ruby/regexp /^[\w\@\-\+\.]+(\.rb)?$/
# Implicitly allow EOS as we use it everywhere. # Implicitly allow EOS as we use it everywhere.
Naming/HeredocDelimiterNaming: Naming/HeredocDelimiterNaming:
ForbiddenDelimiters: ForbiddenDelimiters:
@ -80,10 +84,6 @@ Naming/MethodName:
IgnoredPatterns: IgnoredPatterns:
- '\A(fetch_)?HEAD\?\Z' - '\A(fetch_)?HEAD\?\Z'
# Allow dashes in filenames.
Naming/FileName:
Regex: !ruby/regexp /^[\w\@\-\+\.]+(\.rb)?$/
# Both styles are used depending on context, # Both styles are used depending on context,
# e.g. `sha256` and `something_countable_1`. # e.g. `sha256` and `something_countable_1`.
Naming/VariableNumber: Naming/VariableNumber:

View File

@ -43,7 +43,10 @@ Metrics/ModuleLength:
Naming/PredicateName: Naming/PredicateName:
# Can't rename these. # Can't rename these.
AllowedMethods: is_32_bit?, is_64_bit? AllowedMethods:
- is_a?
- is_32_bit?
- is_64_bit?
Style/HashAsLastArrayItem: Style/HashAsLastArrayItem:
Exclude: Exclude:

View File

@ -18,4 +18,9 @@ class LazyObject < Delegator
def __setobj__(callable) def __setobj__(callable)
@__callable__ = callable @__callable__ = callable
end end
# Forward to the inner object to make lazy objects type-checkable.
def is_a?(klass)
__getobj__.is_a?(klass) || super
end
end end