def edit(object, file=nil)
object = object == TOPLEVEL_BINDING.eval('self') ? nil : object
current_file = if file
FileUtils.touch(file) unless File.exist?(file)
File.new(file)
else
if @file && File.exist?(@file.path) && !object
@file
else
Tempfile.new( object ? ["yobj_tempfile", ".yml"] : ["irb_tempfile", ".rb"] )
end
end
if object
File.open( current_file.path, 'w' ) { |f| f << object.to_yaml }
else
@file = current_file
mtime = File.stat(@file.path).mtime
end
args = Shellwords.shellwords(@editor)
args << current_file.path
current_file.close rescue nil
Exec.system(*args)
if object
File.exists?(current_file.path) ? YAML.load_file(current_file.path) : object
elsif mtime < File.stat(@file.path).mtime
execute
end
end