Class: Object

Inherits:
BasicObject
Defined in:
lib/herpes/extensions.rb

Instance Method Summary collapse

Instance Method Details

#plain_accessor(*names) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/herpes/extensions.rb', line 33

def plain_accessor (*names)
	names.each {|name|
		define_singleton_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_singleton_method "#{name}?" do
			instance_variable_get "@#{name}"
		end

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

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