Created
January 13, 2014 16:30
-
-
Save olistik/8403246 to your computer and use it in GitHub Desktop.
REPL Driven Development
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
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 :-)
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
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)>