0.0
The project is in a healthy, maintained state
Predict Ruby code return values.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

WhatDyaReturn

👼 "What do you return?"

def foo
  if bar
    42
  else
    'baz'
  end
end

🤖 "42 and 'baz'"

Installation

$ gem install what_dya_return

Usage

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.