There are 2 main issues to deal with when posting a technial post on a blog:
1. Syntax Highlighting
There is a wonderful service at The Complex which exports a beautiful Ruby (and other) code, as you see in this blog also.
2. Exampling
You want to example a piece of code you did, how to do it?
try this line:
- def show(&block)
- printf("%-25s>> %s\n", expr = block.call, eval(expr, block.binding).inspect)
- end
for example:
- show {%{ a = [1,2,3] }} ; show {%{ a.slice(1,2) }} ; show {%{ a.map { |x| x**3 } }}
will result in:
- a = [1,2,3] >> [1, 2, 3]
- a.slice(1,2) >> [2, 3]
- a.map { |x| x**3 } >> [1, 8, 27]
0 comments:
Post a Comment