Hi,
I would love to hear your opinion on the idea of “combining RDoc and RSpec to create testable documentation”. Let me explain:
Given you have several RDoc files like this one:
= Examples Some example code snippets.
| # stolen from rosetta code to look at later | |
| def eratosthenes(n) | |
| nums = [nil, nil, *2..n] | |
| (2..Math.sqrt(n)).each do |i| | |
| (i**2..n).step(i){|m| nums[m] = nil} if nums[i] | |
| end | |
| nums.compact | |
| end | |
| p eratosthenes(100) |
| #first stab | |
| h=Hash.new | |
| (File.read "grades.txt").split("\n").each do |pair| | |
| (person, grade)=pair.split ' ' | |
| if h[person] | |
| h[person] << grade.to_i | |
| else | |
| h[person]=[grade.to_i] | |
| end | |
| end |
| ;; fizzbuzz without conditionals in Clojure | |
| ; Simple patten matching using a single map lookup | |
| (defn fizzbuzz [x] | |
| (let [v [(= (mod x 3) 0) (= (mod x 5) 0)]] | |
| ({[true false] "fizz" | |
| [false true] "buzz" | |
| [true true] "fizzbuzz" | |
| [false false] x} v))) |
| import Color exposing (..) | |
| import Graphics.Collage exposing (..) | |
| import Graphics.Element exposing (..) | |
| hexagon : Color -> Form | |
| hexagon clr = outlined (solid clr) (ngon 6 150) | |
| hex_on_a_point : Float -> Color -> Form | |
| hex_on_a_point deg clr = rotate (degrees deg) (hexagon clr) |
| Loop through a given directory's subdirectories ( 1 deep) | |
| In each subdirectory check only files that are older than a day. | |
| If the file is a PDF file or zero byte move to an archive directory and log. | |
| At the end, mail the list of files, if any, to somebody. |
Hi,
I would love to hear your opinion on the idea of “combining RDoc and RSpec to create testable documentation”. Let me explain:
Given you have several RDoc files like this one:
= Examples Some example code snippets.
| .DS_Store | |
| *.csv | |
| h scroll left | |
| j scroll down | |
| k scroll up | |
| l scroll right | |
| gg scroll to top of the page | |
| G scroll to bottom of the page | |
| f activate link hints mode to open in current tab | |
| F activate link hints mode to open in new tab | |
| r reload |
| # Newbie Programmer | |
| def factorial(x) | |
| if x == 0 | |
| return 1 | |
| else | |
| return x * factorial(x - 1) | |
| end | |
| end | |
| puts factorial(6) | |
| puts factorial(0) |
| require 'rss/2.0' | |
| require 'open-uri' | |
| module ApplicationHelper | |
| class EmptyURL < RuntimeError | |
| end | |
| def rss_content(name) | |
| content_object = StaticContent.find_by_name(name) | |
| if content_object.nil? || (Time.now - content_object.updated_at) > 4.hours |