Sexp for Rubyists

Ruby Best Practices - Sexp for Rubyists.

Interesting:

Let me show you an example. First, gem install ruby_parser. Then:

::: {.dp-highlighter} require 'ruby_parser'
require 'pp'

pp RubyParser.new.parse(\<\<-EOF)
def plus_five(n)
n + 5
end
EOF :::

``` {.ruby style="display: none;"} require 'ruby_parser' require 'pp'

pp RubyParser.new.parse(<<-EOF) def plus_five(n) n + 5 end EOF

*Interesting:*

    s(:defn,
     :plus_five,
     s(:args, :n),
     s(:scope,
       s(:block,
         s(:call, s(:lvar, :n), :+, s(:arglist, s(:lit, 5))))))

``` {.ruby style="display: none;"}
require 'ruby_parser'
require 'pp'

pp RubyParser.new.parse(<<-EOF)
def plus_five(n)
  n + 5
end
EOF