Site News #25: Filter Map and Snippets

Graceful.Dev Site News #25

Hi there, graceful devs! Here’s what’s new in the garden…

Content Updates

There’s been just one new addition to the library since the last newsletter: a quick video on Ruby’s filter_map method.

Filter Map in Ruby - Ep. 711

We’ve also released a new freebie into the wild: Pay it Forward, originally published as RubyTapas #17 back in 2012. It’s free to all now, so tell your friends about it!

Other Updates

Recently I’ve started publishing little visual snippets of code on Graceful.Dev’s social media accounts. Here are some samples:

Prefer and to Ternary contact[:blocked] ? contact[:email] : nil # Vs: contact[:blocked] and contact[:email] If the else-case is false-y, an and or 86 is simpler! #ruby
Prefer Spies to Mocks gateway = instance_double(BrevoGateway) expect(gateway ) .to receiveC:create_contact) adapter.add_as_contact(user :) # Vs: gateway = instance_spy(BrevoGateway) adapter.add_as_contact(user :) expect ( gateway ) .to have_received( : create_contact) Most mock objects an be replaced with spy objects. They read better and often require less setup. #ruby #rspec
Quick Method Forwarding class CardHand include Enumerable def initialize (.player, cards') @player = player @cards = cards end def eachf ... ) = @cards.each( ... ) end hand = CardHand. new "Avdi" , ["2 ", "Ko"] hand, grep /&/ # => [‘K@"] With Ruby 3's "endless methods" and ellipsis ( ... ) operator, forwarding methods is easier than ever.

So far they’ve just been going out to social media, but I’m thinking of also publishing them to the site forums, or the blog. I could also keep rounding them up in these newsletters. Let me know what you think!

This is also a good excuse to remind you to follow Graceful.Dev on your favorite social media platforms:

That’s all for this month. Stay graceful!

— Avdi

Responses