Permalink
Browse files

Add Ruby repl acticle

  • Loading branch information...
1 parent 93b15eb commit 937003422af04991697c7b64249a85d6080ba02e @oscardelben committed May 28, 2012
Showing with 33 additions and 0 deletions.
  1. +32 −0 2012/05/ruby-repl.md
  2. +1 −0 README.md
View
32 2012/05/ruby-repl.md
@@ -0,0 +1,32 @@
+# A Simple REPL in Ruby
+
+This is a simple, single line Ruby Repl which shows the basics of how
+irb works. It's super lightweight and minimalist, and probably not very
+usable as it is.
+
+```ruby
+should_exit = false
+_ = nil
+
+print "> "
+
+while !should_exit && line = gets.chomp
+ if line.chomp.strip == 'exit'
+ should_exit = true
+ next
+ end
+
+ begin
+ _ = eval(line)
+ p _
+ rescue Exception => e
+ puts e.message
+ ensure
+ print "> "
+ end
+end
+```
+
+From here, adding multiline support requires some work. Most likely, you
+want to save input in a buffer and use a scanner to detect when input is
+finished. If I have time I'll make one just for fun.
View
1 README.md
@@ -22,6 +22,7 @@ Keep up with the latest changes in Rails edge:
### Random stuff
+* [Ruby REPL](https://github.com/oscardelben/words-about-code/blob/master/2012/05/ruby-repl.md)
* [The Business Tip DHH Gave Me Last Night](https://github.com/oscardelben/words-about-code/blob/master/2012/04/the-business-tip-dhh-gave-me-last-night.md)
### Why Github?

0 comments on commit 9370034

Please sign in to comment.