Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gongo/what_dya_return

Predict Ruby code return values.
https://github.com/gongo/what_dya_return

Last synced: about 4 hours ago
JSON representation

Predict Ruby code return values.

Awesome Lists containing this project

README

        

# WhatDyaReturn

:angel: "What do you return?"

```rb
def foo
if bar
42
else
'baz'
end
end
```

:robot: "42 and 'baz'"

## Installation

$ gem install what_dya_return

## Usage

```rb
WhatDyaReturn::Extractor.new.extract(<<-CODE)
def foo
if bar
42
else
'baz'
end
end
CODE
# => ['42', "'baz'"]

WhatDyaReturn::Extractor.new.extract(<<-CODE)
def foo
return 42 if bar # `bar` is not evaluated in this gem

123
end
CODE
# => ['42', '123']

WhatDyaReturn::Extractor.new.extract(<<-CODE)
def foo
return 42

123
end
CODE
# => ['42']

puts WhatDyaReturn::Extractor.new.extract(<<-CODE)
def foo
do_something
rescue
2
else
3
ensure
4
end
CODE
# => ['3', '2']

puts WhatDyaReturn::Extractor.new.extract(<<-CODE)
def foo
for i in 1..10
1
break 2 if baz
3
end
end
CODE
# => ['2', '1..10']

puts WhatDyaReturn::Extractor.new.extract(<<-CODE)
def foo
1.times do
break 2 if bar
3
end
end
CODE
# => ['2', '1.times']

```

## Caution

`what_dya_return` is an experimental project. There are still many statements that are not supported.

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/gongo/what_dya_return .

## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).