Code Explainers

Code explainers tagged #lambdas

ruby
class NewCommentNotifier < ApplicationNotifier
  deliver_by :database
 
  deliver_by :email do |config|

Multi-channel notifications with Noticed in Rails

notifications delivery-methods fan-out
Intermediate 6 steps
ruby
class User < ApplicationRecord
  has_secure_password
 
  normalizes :email, with: ->(email) { email.strip.downcase }

Normalizing user input in Rails models

normalization validation data integrity
Intermediate 6 steps
ruby
class ParamCoercer
  TYPES = {
    integer: ->(v) { Integer(v) },
    float:   ->(v) { Float(v) },

Coercing request params by schema in Ruby

lambdas type-coercion lookup-table
Intermediate 7 steps