Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > On-the-fly convertion of function modules into include modules

Reply
Thread Tools

On-the-fly convertion of function modules into include modules

 
 
Trans
Guest
Posts: n/a
 
      07-29-2005
.... I've been wanting this functionality for years. I even considered
writing an RCR for it. Now I finally figured out a way to do it in
Ruby. And it was surprisingly simple!

module PromoteSelf
def singleton_method_added( meth)
d = %{
def #{meth}(*args)
#{self.name}.#{meth}(self,*args)
end
}
self.class_eval d
end
end

module String::Format
class << self
include PromoteSelf

def jumble( obj, x, y )
p obj+x+y
end
end
end

String::Format.jumble( "TryMe", '!', '!' )

class String
include Format
end

"TryMe".jumble( '!', '!')

Now I _can_ have my cake and eat it too

T.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help deriving a convertion function on python johnnyukpo@gmail.com Python 2 03-08-2013 12:07 AM
/* #include <someyhing.h> */ => include it or do not include it?That is the question .... Andreas Bogenberger C Programming 3 02-22-2008 10:53 AM
type convertion of an unconstrained output in a port map ygrugni@hotmail.com VHDL 8 02-10-2005 06:53 PM
Convertion php to asp.net : PB lecture fichier .ini isore ASP .Net 0 07-01-2004 05:52 PM



Advertisments