lib/kanji/type.rb
When using method_missing
, fall back on super
. Open
Open
def method_missing(method_name, *args, &block)
if resolve(:value).respond_to?(method_name)
resolve(:value).send(method_name, *args)
else
super(method_name, *args, &block)
- Read upRead up
- Exclude checks
This cop checks for the presence of method_missing
without also
defining respond_to_missing?
and falling back on super
.
Example:
#bad
def method_missing(name, *args)
# ...
end
#good
def respond_to_missing?(name, include_private)
# ...
end
def method_missing(name, *args)
# ...
super
end
Use a guard clause instead of wrapping the code inside a conditional expression. Open
Open
if repo = self.class.resolve(:repo)
- Read upRead up
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression
Example:
# bad
def test
if something
work
end
end
# good
def test
return unless something
work
end
# also good
def test
work if something
end
# bad
if something
raise 'exception'
else
ok
end
# good
raise 'exception' if something
ok
Use ==
if you meant to do a comparison or wrap the expression in parentheses to indicate you meant to assign in a condition. Open
Open
if repo = self.class.resolve(:repo)
- Read upRead up
- Exclude checks
This cop checks for assignments in the conditions of if/while/until.
Example:
# bad
if some_var = true
do_something
end
Example:
# good
if some_var == true
do_something
end