Robert Klemme wrote:

> The singleton class of f knows about instance methods defined in super
> classes.  Which is logical, considering this:

Ah, I was confusing instance_methods() with instance_methods(false).

>>accessors = h.keys - o.methods
>>class << o; self; end.send(:attr_accessor, *accessors)
>>h.each do |key, value|
>>   o.send("#{key}=", value) if accessors.include?(key)
>>end
> 
> Nice and short.  But it has some drawbacks:
> [...]
> 
> You would want ":bar" removed from the keys but it isn't because f.methods
> returns an array of String.  (I assume that symbols are the most likely
> keys for the hash - which might be wrong.)

Hm, I assumed the hash would contain Strings as keys. I guess it could 
be normalized to that.

> Plus, it's not selective enough IMHO because if you just have a setter,
> then that is overwritten.  And if you just have a getter, then no setter
> is defined and you get an error during o.send("#{key}="...).

I was trying to work around methods in Kernel -- I don't think it makes 
sense to have o.p = when you don't have o.p. But I guess the check isn't 
strictly needed anyway. (attr_accessor :p will create a public getter. I 
thought it would create a private one.)