From: Jim Weirich Date: 2006-06-06T20:59:24+09:00 Subject: Re: Ruby and the Open-Closed Principle Jeff Cohen wrote: > For most of my OO career (C++ for a long time, and then C#) I believed > in the OCP very strongly. It's supposedly the cornerstone of OOP, > right? I came across this article today which brought it mind again: > http://www.ddj.com/blog/architectblog/archives/2006/05/open_closed_pri_1.html?cid=GS_blog_arnon > > But I remember my mind getting warped for a few hours when I was first > learning Ruby last year and came across Rails code that extended > existing classes so you could do this: > > 20.minutes.ago > > which I thought was just awesome. Ruby lets me change anything I want > about any class, it seemed, and it was a strange thing to me. > > Of course, I'm not worried about breaking existing code when it's just > my own code, but I'm still violating the open closed principle by > changing the Time class, right? But I think this ability is one of the > things that makes Ruby so great! But isn't this the essence of OCP? The ability to extend a class (open for extensions) without modifying the original code? (which remains closed). -- Jim Weirich -- Posted via http://www.ruby-forum.com/.