0.0
No commit activity in last 3 years
No release in over 3 years
Variants in Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
>= 0
~> 10.0
~> 3.1.0
~> 3.1.3
 Project Readme

Nifty::Variants

Codeship Status for niftyn8/nifty-variants

Gem Version

If you are familiar with variants from a nice language like Haskell try this.

If you don't know what variants are start here

NOTE Nifty::Variants makes use of Refinements which weren't introduced until Ruby 2.1 and as a result no Ruby below 2.1 is supported. You're welcome to write a fancy shim, but I don't recommend it.

Installation

Add this line to your application's Gemfile:

gem 'nifty-variants'

And then execute:

$ bundle install -j2

Usage

nifty-variants makes use of Refinements which were introduced in Ruby 2.1. In order to use it in your class or module simply use it.

class OrderDispatch
  using Nifty::Variants

  def shipit!(order)
    cases order,
      digital: ->(o) { o.email! },
      delivery: ->(o) { o.deliver! },
      else: ->(o) { move_to_error_queue(o) }
  end
end

Contributing

  1. Fork it ( https://github.com/[my-github-username]/nifty-variants/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request