Izzy lets you condense long conditionals into more terse code.
https://github.com/baweaver/izzy
So let’s see it in action: (Person class is in the readme)
brandon = Person.new(‘brandon’, 23, ‘m’)
Boolean matchers
brandon.all_of? :older_than_18?, :male?, :me?, :geek? # => true
brandon.none_of? :younger_than_18?, :female? # => true
brandon.any_of? :male?, :female?, :geek? # => true
=== matchers
brandon.matches_all? name: /^br/, age: (20…30) # => true
brandon.matches_any? name: /br$/, age: (20…30) # => true
brandon.matches_none? name: /br&/, age: (30…40) # => true
brandon.matches_all? name: String, age: Integer
longer_than_3 = -> n { n.length > 3 }
is_odd = -> a { a.odd? }
brandon.matches_all? name: longer_than_3, age: is_odd # => true
longer_than_5 = -> n { n.length > 5 }
greater_than_20 = -> a { a > 20 }
=== multi-matchers
brandon.matches_all?(
name: [/br/, /an/, longer_than_5],
age: [(20…30), greater_than_20]
)
Let me know what you think!