The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Holy Red Snakes! (Cont'd.)

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.
Holy Red Snakes! (Cont'd.) Posted: Jun 3, 2005 12:27 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Red Handed.
Original Post: Holy Red Snakes! (Cont'd.)
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

As previously reported, Python’s Enhancement #340 pitches the addition of anonymous block statements, an effort to give a dash of Ruby to the firmly indented ledges of Python. But let’s not call it Rupy yet. An updated syntax is out in #343 which politely (and exhaustively) asks for a with keyword, which optionally invokes __enter__() and __end__() methods on the borders of the closure.

To give a taste of how this works, here’s an example which uses two blocks to manage temporary redirection of stdout to a file.

 @with_template
 def redirecting_stdout(new_stdout):
   save_stdout = sys.stdout
   sys.stdout = new_stdout
   try:
     yield None
   finally:
     sys.stdout = save_stdout

 with opening(filename, "w") as f:
   with redirecting_stdout(f):
     print "Hello world" 

Anyway, discussion is starting to accumulate today on the WithStatement wiki page.

Read: Holy Red Snakes! (Cont'd.)

Topic: Rubilicious is Uberlicious Previous Topic   Next Topic Topic: Phoenix, AZ Ruby Users Group on Google

Sponsored Links



Google
  Web Artima.com   

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