[ANN] Qo 0.3.0 released


(Brandon Weaver) #1

Qo 0.3.0 is now out, and comes with a shiny new way to do pattern matching:

name_longer_than_three = -> person { person.name.size > 3 }
people_with_truncated_names = people.map(&Qo.match { |m|
  m.when(name_longer_than_three) { |person|
Person.new(person.name[0..2], person.age) }
  m.else(&:itself)
})
# And standalone like a case:Qo.match(people.first) { |m|
  m.when(age: 10..19) { |person| "#{person.name} is a teen that's
#{person.age} years old" }
  m.else { |person| "#{person.name} is #{person.age} years old" }
}

A bit more Scala inspired, and definitely resultant from all the discussion
surrounding the proposal on the bug tracker:

https://bugs.ruby-lang.org/issues/14709

If you're interested in pattern matching in Ruby, jump in, leave a few
comments, let us know what you'd like to see! We're currently making a case
for it, and the more input we get the better.

Thanks for reading, and enjoy!

baweaver