Module: UtilityBelt::Editor

Defined in:
lib/utility_belt/print_methods.rb

Instance Method Summary collapse

Instance Method Details

#edit_class(editor, obj) ⇒ Object

allows you to create a class interactively bit by bit and then edit the whole thing within an editor



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/utility_belt/print_methods.rb', line 20

def edit_class(editor, obj)
  require 'ruby2ruby'
  unless @file
    @file = Tempfile.new("irb_tempfile")
    File.open(@file.path, 'w+') do |f|
      f.write Ruby2Ruby.translate(obj)
    end
  end
  system("#{editor} #{@file.path}")
  Object.class_eval(File.read(@file.path).gsub("\r", "\n"))
rescue Exception => error
  puts @file.path
  puts error
end

#mate_class(obj) ⇒ Object



10
11
12
# File 'lib/utility_belt/print_methods.rb', line 10

def mate_class(obj)
  edit_class 'mate', obj
end

#vi_class(obj) ⇒ Object



14
15
16
# File 'lib/utility_belt/print_methods.rb', line 14

def vi_class(obj)
  edit_class 'vi', obj
end