From: Robert Dober Date: 2009-01-03T00:10:36+09:00 Subject: Re: What does 'Monkey Patching' exactly Mean in Ruby? On Fri, Jan 2, 2009 at 1:42 PM, David A. Black wrote: > I'll put in a plug for what I believe is by far the safest way to > extend core functionality, namely #extend. A classic case is the > desire to have #gsub! not return nil when the string doesn't change. > > module MyGsubBang > def gsub!(*args, &block) > super(*args, &block) || self > end > end > > str = "abc".extend(MyGsubBang) This indeed is a very sensible and elegant way to do things. The true werewolf of dynamic extension (I am happy with MP but there seems to be a consensus against that term...) however is this case # first I am using what I have just learned from David :-P module VersionIndependentInstanceMethods def instance_methos *args, &blk super.map{ |mn| mn.to_sym } end end Class.include Version... class WhatEverOrMaybeEvenACoreClass if instance_methods.include? :xxx then raise IDoNotKnowWhatToDoError, "No I really don't" else def xxx .... end end end Any insights on IDoNotKnowWhatToDoError? Cheers Robert -- It is change, continuing change, inevitable change, that is the dominant factor in society today. No sensible decision can be made any longer without taking into account not only the world as it is, but the world as it will be ... ~ Isaac Asimov