No commit activity in last 3 years
No release in over 3 years
Emulate as similar as possible the smalltalk ifTrue and ifFalse messages.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.9
>= 0
>= 0
~> 10.0
>= 0
 Project Readme

IfTrue-IfFalse

A gem to emulate as similar as possible the smalltalk ifTrue and ifFalse messages.

This gem doesn't only execute the closure, but it returns the value of the closure evaluation.

Installation

Add this line to your application's Gemfile:

gem 'if_true_if_false'

And then execute:

$ bundle

Or install it yourself as:

$ gem install if_true_if_false

Usage

These are the three ways of use this gem

true_condition.if_true { 'ok' } #will execute and return what is into the closure

false_condition.if_true { 'ok' }.if_false { 'false' } #will execute and return what is into the second closure, namely, 'false'

false_condition.if_true { 'ok' } #will return false_condition and won't execute the closure

false_condition.if_false { 'false' } #will return 'false' as expected

Not Possible way of use this Gem

Since the way Ruby treats blocks and semantically wouldn't be right, this case is not taken into account:

any_condition.if_false { 'something' }.if_true { 'other' }

Namely, if_false can't be before if_true

Contributing

  1. Fork it ( https://github.com/gabriel128/if_true_if_false/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

License

This work is under a GPL v3 license.