Skip to content

Instantly share code, notes, and snippets.

@valo
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valo/b318c37dafebcf4424cf to your computer and use it in GitHub Desktop.
Save valo/b318c37dafebcf4424cf to your computer and use it in GitHub Desktop.

Extracting the bar calculation into a separate object, which doesn't know about Foo, allows us to test this code in more isolation and to easily change it in the future, because of its reduced context.

class BarCalculation
def initialize(input1, input2)
@input1 = input1
@input2 = input2
end
def calculate
# ..... the same bad code
end
private
attr_reader :input1, :input2
end
class BetterFoo
private
def bar
new BarCalculator(intpu1, input2).calculate
end
end
class Foo
private
def bar
# .... some really bad code @#$@#$
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment