Gem Version Build Status Maintainability Test Coverage Security Inline docs

Parse yes/no like values

Useful for validating answers of a CLI prompt.

The following case-insensitive values are recognized:

'y', 'yes', 'true', true, '1', 1, 'n', 'no', 'false', false, '0', 0, 'on', 'off'

Enable lenient mode to gracefully handle typos.


Add this line to your application's Gemfile:

gem 'yn'

And then execute:

$ bundle

Or install it yourself as:

$ gem install yn


require 'yn'

# => true

# => false

# => true

# => nil

Yn.parse('abomasum', default: false)
# => false

Yn.parse('mo', lenient: true)
# => false

Unrecognized values return nil.


Yn.parse(input, options?)


Type: unknown

Value that should be converted.


Type: hash


Type: boolean\ Default: false

Use a key distance-based score to leniently accept typos of yes and no.


Type: boolean\ Default: nil

Default value if no match was found.


After checking out the repo, run bin/setup to install dependencies, configure git hooks and create support files.

You can also run bin/console for an interactive prompt that will allow you to experiment.

The health and maintainability of the codebase is ensured through a set of Rake tasks to test, lint and audit the gem for security vulnerabilities and documentation:

rake bundle:audit          # Checks for vulnerable versions of gems 
rake qa                    # Test, lint and perform security and documentation audits
rake rubocop               # Lint the codebase with RuboCop
rake rubocop:auto_correct  # Auto-correct RuboCop offenses
rake spec                  # Run RSpec code examples
rake verify_measurements   # Verify that yardstick coverage is at least 100%
rake yard                  # Generate YARD Documentation
rake yard:junk             # Check the junk in your YARD Documentation
rake yardstick_measure     # Measure docs in lib/**/*.rb with yardstick


Bug reports and pull requests are welcome on GitHub at https://github.com/wilsonsilva/yn. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.


The gem is available as open source under the terms of the MIT License.


This is a port of Sindre Sorhus JavaScript's yn. I'm a big fan of his work!

Code of Conduct

Everyone interacting in the Yn project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.