Skip to content

Instantly share code, notes, and snippets.

@MaxPleaner
Last active June 28, 2017 01:20
Show Gist options
  • Save MaxPleaner/bbf8aadfcce3ea24c1f044c9ca3f78ce to your computer and use it in GitHub Desktop.
Save MaxPleaner/bbf8aadfcce3ea24c1f044c9ca3f78ce to your computer and use it in GitHub Desktop.
module AutoInitializer
  def initialize(*args, **opts, &blk)
  opts.each do |k,v|
  instance_variable_set(“@#{k}”, v)
  end
  super if defined? super
end
end
# Usage
class Foo
attr_reader :bar
include AutoInitializer
end
puts Foo.new(bar: true).bar
# => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment