Skip to content

Instantly share code, notes, and snippets.

@TSMMark
Created February 10, 2021 01:44
Show Gist options
  • Save TSMMark/b28acb43082efb36f3ee9b7694e088d0 to your computer and use it in GitHub Desktop.
Save TSMMark/b28acb43082efb36f3ee9b7694e088d0 to your computer and use it in GitHub Desktop.
Check if a method has kwargs and/or ordered params
# 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