Last active
June 28, 2017 01:20
-
-
Save MaxPleaner/bbf8aadfcce3ea24c1f044c9ca3f78ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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