coding style - Tightening Up Ruby Code, Making Small Methods -


i have method reported rubocop long: allowed 7 lines per method. here's offending method:

def on(definition, visit = false, &block)   if @active.is_a?(definition)     block.call @active if block     return @active   end    @active = definition.new   @active.load if visit    block.call @active if block    @active end 

i going convert top if condition guard clause, don't see how that.

i tried combining lines 7 , 8 this:

@active = definition.new().load if visit 

but not work.

i can't leave rubocop violations active nor can change tolerances.

this reduce 2 lines:

def on(definition, visit = false, &block)   unless @active.is_a?(definition)       @active = definition.new     @active.load if visit   end    block.call @active if block   @active end 

Comments