Module: Treequel::AttributeDeclarations

Overview

A collection of attribute declaration functions

Class Method Summary collapse

Class Method Details

.predicate_attr(*symbols) ⇒ Object

Declare predicate accessors for the attributes associated with the specified symbols.



299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/treequel/mixins.rb', line 299

def predicate_attr( *symbols )
	symbols.each do |attrname|
		define_method( "#{attrname}?" ) do
			instance_variable_defined?( "@#{attrname}" ) &&
				instance_variable_get( "@#{attrname}" ) ? true : false
		end
		define_method( "#{attrname}=" ) do |newval|
			instance_variable_set( "@#{attrname}", newval ? true : false )
		end
		alias_method "is_#{attrname}?", "#{attrname}?"
	end
end