Method: Filigree::TypedClass::ClassMethods#default_constructor

Defined in:
lib/filigree/types.rb

#default_constructor(strict = false) ⇒ void

This method returns an undefined value.

Define the default constructor for the including class.

Parameters:

  • strict (Boolean) (defaults to: false)

    To use strict checking or not



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/filigree/types.rb', line 99

def default_constructor(strict = false)
	class_eval do
		if strict
			def initialize(*vals)
				if self.class.typed_ivars.length != vals.length
					raise ArgumentError, "#{self.class.typed_ivars.length} arguments expected, #{vals.length} given."
				end

				self.set_typed_ivars(vals)
			end
		else
			def initialize(*vals)
				self.set_typed_ivars(vals)
			end
		end
	end
end