The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Small Ruby CLI Improvements (Part 4): Edit Ruby Objects Using yaml

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
Jan Lelis

Posts: 136
Nickname: rbjl
Registered: Aug, 2009

Jan Lelis is an IT student from Dresden/Germany
Small Ruby CLI Improvements (Part 4): Edit Ruby Objects Using yaml Posted: Mar 8, 2011 2:06 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Jan Lelis.
Original Post: Small Ruby CLI Improvements (Part 4): Edit Ruby Objects Using yaml
Feed Title: rbJ*_*L.net
Feed URL: http://feeds.feedburner.com/rbJL
Feed Description: Hi, I am a fan of Ruby and like to explore it and the world around ;). So I started this blog, where I am publishing code snippets, tutorials for beginners as well as general thoughts about Ruby, the web or programming in general.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Jan Lelis
Latest Posts From rbJ*_*L.net

Advertisement

Somehow, I stumbled upon this useful little script by _why:

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.

Listing 1
/48/aorta.rb ruby
# why the luck stiff's "object aorta"
# http://rubyforge.org/snippet/detail.php?type=snippet&id=22

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
CC-BY (DE)

Read: Small Ruby CLI Improvements (Part 4): Edit Ruby Objects Using yaml

Topic: Small Ruby CLI Improvements (Part 4): Edit Ruby Objects Using yaml Previous Topic   Next Topic Topic: Eloquent Ruby Review

Sponsored Links



Google
  Web Artima.com   

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