class Module
Public Instance Methods
class_accessor( klass, *symbols )
click to toggle source
# File lib/ckuru-tools.rb, line 22 def class_accessor( klass, *symbols ) symbols.each do |symbol| module_eval( "def #{symbol}() @#{symbol}; end" ) module_eval( " def #{symbol}=(val) raise ArgumentError.new(self.send(:class).send(:to_s) + ': argument to #{symbol} must be a class') unless val.is_a? Class raise ArgumentError.new(self.send(:class).send(:to_s) + ': #{symbol} must be a #{klass}') unless val.inherits_from? #{klass} @#{symbol} = val end" ) end end
instance_of_class_accessor( klass, *symbols )
click to toggle source
# File lib/ckuru-tools.rb, line 8 def instance_of_class_accessor( klass, *symbols ) symbols.each do |symbol| module_eval( "def #{symbol}() @#{symbol}; end" ) module_eval " def #{symbol}=(val) unless val.class.inherits_from? #{klass} raise ArgumentError.new(self.send(:class).send(:to_s) + ': #{symbol} must be a #{klass}, not one of ' + val.class.ancestors.to_s) end @#{symbol} = val self.send(:after_#{symbol}_set) if self.respond_to?(:after_#{symbol}_set) end" end end
typed_array_accessor(klass,*symbols)
click to toggle source
raise ArgumentError.new(“assignment must be of class CkuruTools::TypedArray
, not #{arr.class}”) unless arr.instance_inherits_from? CkuruTools::TypedArray
raise ArgumentError.new(“TypedArray must require #{klass}”) unless arr.required_type == #{klass}
# File lib/ckuru-tools.rb, line 36 def typed_array_accessor(klass,*symbols) symbols.each do |symbol| module_eval( "def #{symbol}() @#{symbol}; end" ) module_eval <<"EOF" def #{symbol}=(arr) @#{symbol} = CkuruTools::TypedArray.new(#{klass}) arr.each do |elem| @#{symbol}.push elem end @#{symbol} end EOF end end