The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
FreakyFreaky Now Resumes Its Usual Sandly Self

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.
FreakyFreaky Now Resumes Its Usual Sandly Self Posted: Nov 15, 2006 12:08 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Red Handed.
Original Post: FreakyFreaky Now Resumes Its Usual Sandly Self
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

I know it’s been out of sorts for the past month, but the big checkin is, in fact, IN. The big deal today: class and module references.

 svn co http://code.whytheluckystiff.net/svn/sandbox/trunk sandbox
 cd sandbox
 ruby setup.rb

Like, say you want to give a sandbox some limited access to a database:

 require 'sandbox'
 require 'mysql'
 # setup a proxy module
 module Database
 @@db = Mysql.connect(...)
 def self.query(str)
 @@db.query(str).fetch_hash
 end
 end
 # use the proxy module inside the sandbox
 sand = Sandbox.safe
 sand.ref Database
 sand.eval("Database.query('SELECT * FROM apples')")

Well, this is a bit contrived. But, you know?

And it’s safe. In the sandbox, the Database module is actually a Database class, descended from BoxedClass, which has a method_missing which will restore the original Ruby environment, make the call, and marshal the results back to the sandbox. So the query call in the box does get its Hash.

Read: FreakyFreaky Now Resumes Its Usual Sandly Self

Topic: Rails: Textmate Footnotes Previous Topic   Next Topic Topic: Nitro Og 0.40.0

Sponsored Links



Google
  Web Artima.com   

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