Created
February 10, 2021 01:44
-
-
Save TSMMark/b28acb43082efb36f3ee9b7694e088d0 to your computer and use it in GitHub Desktop.
Check if a method has kwargs and/or ordered params
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Has kwargs? (Keyword arguments) | |
def method_has_keyword_parameters?(method) | |
method.parameters.any? do |param| | |
type, _name = param | |
type == :key | |
end | |
end | |
# Has ordered arguments? | |
def method_has_ordered_parameters?(method) | |
method.parameters.any? do |param| | |
type, _name = param | |
%i[req opt].include?(type) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment