Sha256: 5d6b70d623e5ff1bbcb6bb5b1404894a9ec06b338b8f3b005f7aa30f7af97cc1
Contents?: true
Size: 675 Bytes
Versions: 1
Compression:
Stored size: 675 Bytes
Contents
module SmartInit def is_callable define_singleton_method :call do |*parameters| new(*parameters).call end end 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-1.1.0 | lib/smart_init/main.rb |