Browse | Submit A New Snippet | Create A Package

 

Why the luck stiff's "Object Aorta"

Type:
Function
Category:
Other
License:
Other
Language:
Ruby
 
Description:
From Why's blog:
* Lovely, Simple, Prismatic
I say it's prismatic because this little snippy marries a few of my true loves together. Allow users to edit Ruby objects in YAML using your editor of choice.

Versions Of This Snippet::

Dima Sabanin
Snippet ID Download Version Date Posted Author Delete
271.02004-02-02 05:11Dima Sabanin

Download a raw-text version of this code by clicking on "Download Version"

 


Latest Snippet Version: :1.0

require 'yaml'
def aorta( obj )
  tempfile = File.join('/tmp',"yobj_#{ Time.now.to_i }")
  File.open( tempfile, 'w' ) { |f| f << obj.to_yaml }
  system( "#{ ENV['EDITOR'] || 'vi' } #{ tempfile }" )
  return obj unless File.exists?( tempfile )
  content = YAML::load( File.open( tempfile ) )
  File.delete( tempfile )
  content
end

		

Submit a new version

You can submit a new version of this snippet if you have modified it and you feel it is appropriate to share with others..