Project

if

0.0
No commit activity in last 3 years
No release in over 3 years
A heavily Smalltalk-inspired implementation of the if conditional without using keywords.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 3.2
 Project Readme

if Build Status

See "Implementing if in Ruby" for more information.

Requirements

This library is tested on Ruby 1.8.7 and later but benefits from Ruby 1.9's hash and lambda literal syntax.

"truthy".if -> { "I'm true!" }, else: -> { "I'm false!" }
# vs.
"truthy".if proc { "I'm true!" }, :else => proc { "I'm false!" }

Usage

require "if"

"Some truthy object".if -> { "I'm true!" }, else: -> { "I'm false!" }
#=> "I'm true!"

nil.if -> { "I'm true!" }, else: -> { "I'm false!" }
#=> "I'm false!"

# Or, if you only care about side-effects and not return value:

"Some truthy object"
  .if_true { puts "I'm true!" }
  .if_false { puts "I'm false!" }
# "I'm true!"
#=> "Some truthy object"

nil
  .if_true { puts "I'm true!" }
  .if_false { puts "I'm false!" }
# "I'm false!"
#=> nil

License

Copyright © 2015 Paul Mucur

Distributed under the MIT License.