Sha256: af75ac3bd8f05eff3c3c296bc2a4cba26de9c46b4e8216f616eec9bf08e9d4ac
Contents?: true
Size: 563 Bytes
Versions: 1
Compression:
Stored size: 563 Bytes
Contents
module SmartInit def initialize_with *attributes define_method :initialize do |*parameters| if attributes.count != parameters.count raise ArgumentError, "wrong number of arguments (given #{parameters.count}, expected #{attributes.count})" end attributes.zip(parameters).each do |pair| name = pair[0] value = pair[1] instance_variable_set("@#{name}", value) end end instance_eval do private attr_reader *attributes end end end class SmartInit::Base extend SmartInit end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
smart_init-0.1.0 | lib/smart_init/main.rb |