Hi, this blog is no longer maintained, my new blog is here

Ruby On Rails and a Conning Israeli entrepreneur

Ruby For bloggers

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:

  1. def show(&block)
  2. printf("%-25s>> %s\n", expr = block.call, eval(expr, block.binding).inspect)
  3. end

for example:
  1. show {%{ a = [1,2,3] }} ; show {%{ a.slice(1,2) }} ; show {%{ a.map { |x| x**3 } }}  

will result in:
  1. a = [1,2,3]                 >>  [1, 2, 3]  
  2. a.slice(1,2)                 >>  [2, 3]  
  3. a.map { |x| x**3 }      >>  [1, 8, 27]  

0 comments:


The Web Ask eizesus.com

Subscribe

    follow me on Twitter

    Twiters Around

    About Me

    My photo
    I am a web developer for more than 9 years, managed, cried, coded, designed and made money in this industry. now trying to do it again.

    Labels