Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@olistik
Created January 13, 2014 16:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olistik/8403246 to your computer and use it in GitHub Desktop.
Save olistik/8403246 to your computer and use it in GitHub Desktop.
REPL Driven Development
$ irb
> class Person
attr_accessor :name
end
> person = Person.new name: 'Alejandro'
> current_session.dump('world.session')
> exit
$ irb
> person.name # => NameError...
> load_session('world.session')
> person.name # => 'Alejandro'
> Person.source.to_s # => "class Person\nattr_accessor :name\nend"
> edit Person # fires up the editor showing the source code for Person and updates the code upon editor save
> module A
def foo
end
end
> module A::B
def spam
end
end
> class A::C
def egg
end
end
> edit A # fires up the editor showing a subtree with the following files: a.rb, a/b.rb, a/c.rb
@breezeight
Copy link

With Pry:
[1] pry(main)> def hello
[1] pry(main)* puts "Hello!"
[1] pry(main)* end
=> :hello
[2] pry(main)> hello
Hello!
=> nil
[3] pry(main)> edit hello
[5] pry(main)> hello
HELLO! (Edited)
=> nil
[6] pry(main)>

@olistik
Copy link
Author

olistik commented Jan 13, 2014

@breezeight

cool :-)

unfortunately it doesn't work with class definitions:

[7] pry(main)> class Asd
[7] pry(main)* def foo
[7] pry(main)* end
[7] pry(main)* end
=> :foo
[8] pry(main)> edit Asd
Error: Cannot find a file for Asd!

By the way it's a good start :-)

@breezeight
Copy link

you can edit a single method:
[1] pry(main)> class A
[1] pry(main)* def hello
[1] pry(main)* puts "Hello"
[1] pry(main)* end
[1] pry(main)* end
=> :hello
[2] pry(main)> edit A #ERROR
Error: Cannot find a file for A!

[3] pry(main)> edit A#hello #IT WORKS
[6] pry(main)> A.new.hello
Hello!!!
=> nil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment