class RuboCop::Cop::Style::OptionalBooleanParameter
end
puts bar
def some_method(bar = false)
# good
@example AllowedMethods: [‘some_method’]
end
puts bar
def some_method(bar: false)
# good
end
puts bar
bar = options.fetch(:bar, false)
def some_method(options = {})
# bad - common hack before keyword args were introduced
end
puts bar
def some_method(bar = false)
# bad
@example
implicitly change behaviour.
This cop is unsafe because changing a method signature will
@safety
These are customizable with ‘AllowedMethods` option.
boolean arguments when defining methods. `respond_to_missing?` method is allowed by default.
This cop checks for places where keyword arguments can be used instead of
def format_message(argument)
def format_message(argument) source = argument.source format(MSG, original: source, replacement: source.sub(/\s+=/, ':')) end
def on_def(node)
def on_def(node) return if allowed_method?(node.method_name) node.arguments.each do |arg| next unless arg.optarg_type? add_offense(arg, message: format_message(arg)) if arg.default_value.boolean_type? end end