Project

any

0.01
No commit activity in last 3 years
No release in over 3 years
An Any type, much like Scala, that matches anything.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.16
= 0.3.0
~> 10.0
~> 3.0
 Project Readme

Any

Any is a simple gem. When you compare it against anything, it's always true.

This is a play at Scala's Any type, mostly used for pattern matching type techniques.

Credits

Thanks to @soffes for allowing me to repurpose the gem Any!

The original will be maintained at versions 0.0.1 and 0.0.2 from this repo

Usage

Note that I'm using Qo here. If these two issues are added in Ruby 2.6+ it'll enable us to do this without the need for Qo:

I've commented on each to note this.

For now, I will leave Qo in the specs so that we don't have a hard dependency on 2.6+, especially considering that at the time of writing this it's still in development.

require 'qo' # gem install qo @ v0.3.0

case ['Foo', 25]
when Qo[/^F/, Any] then true
else false
end
# => true

case {id: 1, name: 'foo', age: 42}
when Qo[id: Any, name: /^f/, age: Any] then true
else false
end
# => true

case {id: 1, name: 'foo'}
when Qo[id: Any, name: /^f/, age: Any] then true
else false
end
# => false

Qo behaves much like the proposals, except in that it's permissive for Arrays of mismatched lengths and works with Objects.

In 2.6+, assuming the two above are accepted, you could do this:

case ['Foo', 25]
when [/^F/, Any] then true
else false
end
# => true

case {id: 1, name: 'foo', age: 42}
when {id: Any, name: /^f/, age: Any} then true
else false
end
# => true

case {id: 1, name: 'foo'}
when {id: Any, name: /^f/, age: Any} then true
else false
end
# => false

Installation

Add this line to your application's Gemfile:

gem 'any'

And then execute:

$ bundle

Or install it yourself as:

$ gem install any

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/baweaver/any. 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.

License

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

Code of Conduct

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