Skip to content

Instantly share code, notes, and snippets.

@vladiim
Created May 19, 2012 00:28
Show Gist options
  • Select an option

  • Save vladiim/2728302 to your computer and use it in GitHub Desktop.

Select an option

Save vladiim/2728302 to your computer and use it in GitHub Desktop.
# `factorize` allows Classes to create new class methods it does this by # calling public_method(:new) on the class rather than directly calling new # therebye ensuring single responsibility is followed
module Factorizer
# `factorize` allows Classes to create new class methods it does this by
# calling public_method(:new) on the class rather than directly calling new
# therebye ensuring single responsibility is followed
def factorize(klass, *attrs)
klass = Object.const_get(klass)
klass_source(klass).call(*attrs)
end
private
def klass_source(klass)
klass.public_method(:new)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment