The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Monkeypytching?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Red Handed

Posts: 1158
Nickname: redhanded
Registered: Dec, 2004

Red Handed is a Ruby-focused group blog.
Monkeypytching? Posted: Jul 18, 2006 10:52 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Red Handed.
Original Post: Monkeypytching?
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Red Handed
Latest Posts From RedHanded

Advertisement

So now some Pythonistas want monkeypatching! Will the snakes recoil? Hardly, in the comments, Harry Fuecks offers up:

 class Foo:
 def __init__(self):
 self.x = "x = 1" 
 self.y = "y = 2" 
 def showx(self):
 print self.x
 def showy(self):
 print self.y
 if __name__ == '__main__':
 # Attach at runtime...
 Foo.showy = showy
 f2 = Foo()
 f2.showx()
 f2.showy()

It’s priceless how Harry’s code gets flattened in the comments. I mean this is one example where the nesting is really essential. I’m not saying my comment layout is any better. We’ve had a real mess with plus signs here. (Nicked from Simon.)

Read: Monkeypytching?

Topic: Will the Enterprise change Ruby, or will Ruby change the Enterprise? Previous Topic   Next Topic Topic: Ruby and Python Bindings for GEOS

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use