From: George Moschovitis Date: 2004-10-12T17:09:36+09:00 Subject: Re: [Q] case based on object class > If the original poster is still reading, what is the real > application? Is there some reason you need to know the class, or do you > just need to assure that the class has some behaviour? here is a snippet from the real application (ndb). I want to make the following code more elegant (I dont care for efficiency this code only runs once :)) 102 s, klass = prop.symbol, prop.klass 103 104 module_eval %{ 105 def #{s} 106 return @#{s} 107 end 108 109 def #{s}=(val) 110 @#{s} = val 111 end 112 113 def __force_#{s}(val) 114 @#{s} = } + case klass.name 115 when Fixnum.name 116 "val.to_i()" 117 when String.name 118 "val.to_s()" 119 when Float.name 120 "val.to_f()" 121 when Time.name 122 "Time.parse(val.to_s())" 123 when TrueClass.name, FalseClass.name 124 "val.to_i() > 0" 125 else 126 "val" 127 end + %{ 128 end 129 } 130 end regards, George Moschovitis -- www.navel.gr | tel: +30 2106898050 | fax: +30 2106898437 Navel does not accept liability for any errors, viruses or omissions in the contents of this message. The full corporate policy is available on our site. have fun: www.joy.gr