class_eval better than reopening classes?

1 view
Skip to first unread message

Alex Wayne

unread,
May 30, 2008, 4:50:46 PM5/30/08
to rubyonra...@googlegroups.com
I came accross this snippet from the docrails project

"When monkey-patching existing classes it's often better to use
`class_eval` instead of opening the class directly."

From this commit:
http://github.com/lifo/docrails/commit/60e37868e40ac11f07cbda81f24dcdb0a9c68783#L0R275

First of all, is this right? And second, why? Does it make a
difference if this is a in the context of a rails plugin?
--
Posted via http://www.ruby-forum.com/.

Frederick Cheung

unread,
May 30, 2008, 5:14:41 PM5/30/08
to Ruby on Rails: Talk


On May 30, 9:50 pm, Alex Wayne <rails-mailing-l...@andreas-s.net>
wrote:
> I came accross this snippet from the docrails project
>
>   "When monkey-patching existing classes it's often better to use
> `class_eval` instead of opening the class directly."
>
> From this commit:http://github.com/lifo/docrails/commit/60e37868e40ac11f07cbda81f24dcd...

http://ola-bini.blogspot.com/2008/05/dynamically-created-methods-in-ruby.html
says the opposite

Fred
Reply all
Reply to author
Forward
0 new messages