From: Leslie Viljoen Date: 2006-05-07T01:30:06+09:00 Subject: Re: Sharp knives and glue On 5/6/06, Dick Davies wrote: > On 06/05/06, Leslie Viljoen wrote: > > > ie. my function needs strings in culy braces. So the natural thing for > > me would be this: > > > > class String > > def curlify > > "{"+self+"}" > > end > > end > > > > This is where I need the curlies and it makes sense for them to be there. > > But then you've tampered with the very fabric of reality (HPL would be > proud) [1]. > > You could just modify the object you were passed: > > def func_that_needs_strings_to_have_a_curlify_method(str) > def str.curlify > "{" + self + "}" > end > > # do something with str > end > > This has the side effect on permanently adding a curlify method to whatever > str points at, but not all Strings in the universe. > > You might not want that, of course - but it has less impact than > modifying all strings. (If you only wanted that method to apply with your > function, you could dup the object you were passed before meddling > with it. Yes... and if I have 50 functions that need curlify? How would I add curlify to all strings that are passed to methods in my module, for example?