Permalink
Browse files

first commit

  • Loading branch information...
txus committed Oct 7, 2012
0 parents commit 5198cd60700aa91224b2b408c17c5eef43890982
Showing with 599 additions and 0 deletions.
  1. +17 −0 .gitignore
  2. +1 −0 .rvmrc
  3. +4 −0 Gemfile
  4. +22 −0 LICENSE.txt
  5. +69 −0 README.md
  6. +10 −0 Rakefile
  7. +5 −0 bin/explain
  8. +10 −0 examples/person.rb
  9. +19 −0 explain.gemspec
  10. +10 −0 lib/explain.rb
  11. +3 −0 lib/explain/version.rb
  12. +337 −0 lib/explain/visitor.rb
  13. +90 −0 test/explain/visitor_test.rb
  14. +2 −0 test/test_helper.rb
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
1 .rvmrc
@@ -0,0 +1 @@
+rvm use rbx-head@explain --create
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in explain.gemspec
+gemspec
@@ -0,0 +1,22 @@
+Copyright (c) 2012 Josep M. Bach
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,69 @@
+# explain
+
+Explain explains your Ruby code in natural language. It is intended to be a
+tool for beginners who aren't yet very familiar with programming.
+
+It is a work in progress (a bit rough on the edges), so don't be mad. It will
+get better over time ;)
+
+(Explain runs only on Rubinius.)
+
+## Installation
+
+Install Rubinius if you don't have it yet:
+
+ $ rvm install rbx-head
+ $ rvm use rbx-head
+
+Install explain as a gem:
+
+ $ gem install explain
+
+## Usage
+
+Given some example Ruby code, for example this in `examples/person.rb`:
+
+```ruby
+class Person
+ def walk(distance)
+ @distance += distance
+ @hunger += 2
+ end
+
+ def eat(food)
+ @hunger -= food.nutritional_value
+ end
+end
+```
+
+We execute `explain` from the command line:
+
+ $ explain examples/person.rb
+
+And it will output:
+
+ Let's describe the general attributes and behavior of any Person.
+
+ A Person can **walk**, given a specific distance. This is described as
+ follows: its distance will be its distance plus what we previously defined as
+ `distance`. Finally we return its hunger will be its hunger plus the number
+ 2..
+
+ A Person can **eat**, given a specific food. This is described as follows:
+ Finally we return its hunger will be its hunger minus the result of calling
+ **nutritional_value** on what we previously defined as `food`..
+ And with this we're done describing a Person.
+
+## Contributing
+
+1. Fork it
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Add some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create new Pull Request
+
+## Who's this
+
+This was made by [Josep M. Bach (Txus)](http://txustice.me) under the MIT
+license. I'm [@txustice](http://twitter.com/txustice) on twitter (where you
+should probably follow me!).
@@ -0,0 +1,10 @@
+require "bundler/gem_tasks"
+
+require 'rake/testtask'
+Rake::TestTask.new do |t|
+ t.libs << "test"
+ t.test_files = FileList['test/**/*_test.rb']
+ t.verbose = true
+end
+
+task :default => :test
@@ -0,0 +1,5 @@
+#!/usr/bin/env rbx
+
+$: << 'lib'
+require 'explain'
+puts Explain.explain File.read(ARGV.first)
@@ -0,0 +1,10 @@
+class Person
+ def walk(distance)
+ @distance += distance
+ @hunger += 2
+ end
+
+ def eat(food)
+ @hunger -= food.nutritional_value
+ end
+end
@@ -0,0 +1,19 @@
+# -*- encoding: utf-8 -*-
+lib = File.expand_path('../lib', __FILE__)
+$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
+require 'explain/version'
+
+Gem::Specification.new do |gem|
+ gem.name = "explain"
+ gem.version = Explain::VERSION
+ gem.authors = ["Josep M. Bach"]
+ gem.email = ["josep.m.bach@gmail.com"]
+ gem.description = %q{TODO: Write a gem description}
+ gem.summary = %q{TODO: Write a gem summary}
+ gem.homepage = ""
+
+ gem.files = `git ls-files`.split($/)
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
+ gem.require_paths = ["lib"]
+end
@@ -0,0 +1,10 @@
+require "explain/version"
+require "explain/visitor"
+
+module Explain
+ def self.explain(code)
+ visitor = Visitor.new
+ visitor.visit(code.to_ast)
+ visitor.output
+ end
+end
@@ -0,0 +1,3 @@
+module Explain
+ VERSION = "0.0.1"
+end
Oops, something went wrong.

0 comments on commit 5198cd6

Please sign in to comment.