[Facebooker-talk] view problem
kevin lochner
klochner at gmail.com
Fri Jan 23 18:39:16 EST 2009
thanks. There was one problem with that solution - it wouldn't let
you assign already instantiated
objects to the member variables. I'm now looking at the following:
def hash_settable_writer(symbol, klass)
define_method("#{symbol}=") do |value|
if value.kind_of?(Hash)
instance_variable_set("@#{symbol}",klass.from_hash(value))
elsif value.kind_of?(klass)
instance_variable_set("@#{symbol}", value)
end
end
end
should be able to get a patch & tests out this weekend.
- kevin
On Jan 23, 2009, at 6:33 PM, Mike Mangino wrote:
> I think that makes sense. I've added you as a committer to the
> project. Feel free to commit a patch with tests!
>
> Mike
>
> On Jan 23, 2009, at 6:06 PM, kevin lochner wrote:
>
>> How about setting to nil if value isn't a hash. The object is
>> hash_settable, and it doesn't
>> seem to make sense to assign it an object of arbitrary class
>> (string) if it's not given a hash
>> from which to populate:
>>
>> def hash_settable_writer(symbol, klass)
>> define_method("#{symbol}=") do |value|
>> instance_variable_set("@#{symbol}", value.kind_of?(Hash) ?
>> klass.from_hash(value) : nil)
>> end
>> end
>>
>> On Jan 23, 2009, at 5:52 PM, kevin lochner wrote:
>>
>>> def hash_settable_writer(symbol, klass)
>>> define_method("#{symbol}=") do |value|
>>> instance_variable_set("@#{symbol}", value.kind_of?(Hash) ?
>>> klass.from_hash(value) : value)
>>> end
>>> end
>>
>
> --
> Mike Mangino
> http://www.elevatedrails.com
>
>
>
More information about the Facebooker-talk
mailing list