1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
# proc_to_ast
[](http://badge.fury.io/rb/proc_to_ast)
[](https://github.com/joker1007/proc_to_ast/actions/workflows/rspec.yml)
Add `#to_ast` method to Proc.
`#to_ast` convert Proc to `Parser::AST::Node`, using [parser](https://github.com/whitequark/parser "whitequark/parser") gem.
## Installation
Add this line to your application's Gemfile:
gem 'proc_to_ast'
And then execute:
$ bundle
Or install it yourself as:
$ gem install proc_to_ast
## Usage
```ruby
require 'proc_to_ast'
foo = proc { p(1 + 1) }
foo.to_ast
# =>
# (block
# (send nil :proc)
# (args)
# (send nil :p
# (send
# (int 1) :+
# (int 1))))
foo.to_source
# => "proc do\n p(1 + 1)\nend"
foo.to_source(highlight: true)
# => "proc \e[32mdo\e[0m\n p(\e[1;34m1\e[0m + \e[1;34m1\e[0m)\n\e[32mend\e[0m"
```
## Contributing
1. Fork it ( https://github.com/[my-github-username]/proc_to_ast/fork )
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 a new Pull Request
|