The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Sam Ruby Funnels Down Rails

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.
Sam Ruby Funnels Down Rails Posted: Aug 9, 2005 4:01 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Red Handed.
Original Post: Sam Ruby Funnels Down Rails
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

Since David’s gone all this week, I’ll pick up some of the Rails news, how about? Especially when the Rails news gets us back into hacking plain old Ruby code. As is the case with Sam Ruby, who’s tinkering with Rails outside of the framework—he calls it his Rails Confidence Builder.

The script is sort of a stream-of-consciousness walk through ActiveRecord insertion and retrieval. Within the framework, the parts of this script get placed in different subdirectories, to ensure the MVC parts stay organized. I’ve annotated Sam’s example with brief comments indicating where each piece would go in a Rails app. Keep in mind that the db/entries.sql would be described in plain SQL and the config/database.yml would be described in YAML.

Sam uses Ruby’s pipe opener to communicate with MySQL and notes how the closure neatly tucks the ends for the resource.

While IO.popen can be used as a traditional function, returning a stream that you can write to and ultimately are responsible for closing, I’m making use of another idiom: passing a block to the function. IO.popen will bind the file handle to the argument you specify, and take care of ensuring that the pipe is closed properly when you exit the scope of the block. Sweet!

Yeah, I’m so glad I don’t have to figure out where to put IO.close ever again. (Seen on intertwingly.)

Read: Sam Ruby Funnels Down Rails

Topic: Shutting the Scary Door Previous Topic   Next Topic Topic: Pluto Is Not A Planet

Sponsored Links



Google
  Web Artima.com   

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