What have you found for these years?

2009-01-09

reserved methods for property getter

http://datamapper.lighthouseapp.com/projects/20609/tickets/756

It should not override internal methods for property getter.

I notice that there's a guard around defining property getter in
dkubb/dm-core, which is "unless model.instance_methods(false).include?
(getter)". However, this didn't help much since instance_methods(false)
would return only instance methods for client model (e.g. User). In
addition, Ruby 1.8 would return method names in String, not Symbol, so
it's always false in Ruby 1.8. (and Ruby 1.9 returns symbols.)

But change this to "unless model.instance_methods(true).include?
(getter)" is too aggressive since you cannot use "property :id"
due to there's Object#id in Ruby 1.8 which is deprecated but not
removed in this manner. I found this problem when I defined a
property called :model, and I got stack overflow simply because
calling User.first (it shocks me...).

Other property names like :send, :class, :save, :original_values,
etc. would cause different errors in different places. It's hard
to find out which name was used internally. I think perhaps we
should keep a list of "reserved methods" for property getter,
and warn people when they touched reserved methods or raise
an error, or silently ignore them just like current guard
"unless model.instance_methods(false).include?(getter)" ?

I could try to search for the list if it should be kept.

cheers,
Jen-Shin

0 retries:

Post a Comment

Note: Only a member of this blog may post a comment.



All texts are licensed under CC Attribution 3.0