Class: Module

Inherits:
Object show all
Defined in:
lib/herpes/extensions.rb

Instance Method Summary collapse

Instance Method Details

#plain_accessor(*names) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/herpes/extensions.rb', line 65

def plain_accessor (*names)
	names.each {|name|
		define_method name do |*args|
			if args.empty?
				instance_variable_get "@#{name}"
			else
				value = (args.length > 1) ? args : args.first

				if value.nil?
					remove_instance_variable "@#{name}"
				else
					instance_variable_set "@#{name}", value
				end
			end
		end

		define_method "#{name}?" do
			instance_variable_get "@#{name}"
		end

		define_method "#{name}!" do
			instance_variable_set "@#{name}", true
		end

		define_method "no_#{name}!" do
			instance_variable_set "@#{name}", false
		end
	}
end