Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joker1007/proc_to_ast
convert Proc to Parser::AST::Node, using parser gem.
https://github.com/joker1007/proc_to_ast
Last synced: 2 days ago
JSON representation
convert Proc to Parser::AST::Node, using parser gem.
- Host: GitHub
- URL: https://github.com/joker1007/proc_to_ast
- Owner: joker1007
- License: mit
- Created: 2014-04-05T11:24:33.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-05-04T12:32:27.000Z (6 months ago)
- Last Synced: 2024-09-02T16:55:52.749Z (2 months ago)
- Language: Ruby
- Homepage:
- Size: 21.5 KB
- Stars: 11
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# proc_to_ast
[![Gem Version](https://badge.fury.io/rb/proc_to_ast.svg)](http://badge.fury.io/rb/proc_to_ast)
[![RSpec](https://github.com/joker1007/proc_to_ast/actions/workflows/rspec.yml/badge.svg)](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