Sha256: 6bfe8c95bc9a7f3ba53e2e22003683f9893059b09c330f59fcc465ed50cab675

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

# 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).

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
what_dya_return-0.2.1 README.md
what_dya_return-0.2.0 README.md