Excerpt
def demo(**attributes)
case attributes
in name:, **nil then puts "Name: #{name}."
in name:, label: String => label then puts "Name: #{name}, Label: #{label}."
in {} then puts "No attributes found."
else puts "Unable to match: #{attributes}."
end
end
demo name: "demo" # "Name: demo."
demo name: "demo", label: "Demo" # "Name: demo, Label: Demo."
demo # "No attributes found."
demo x: 1, y: 2 # "Unable to match: {:x=>1, :y=>2}."
def demo(**attributes)
case attributes
in name:, **nil then puts "Name: #{name}."
in name:, label: String => label then puts "Name: #{name}, Label: #{label}."
in {} then puts "No attributes found."
else puts "Unable to match: #{attributes}."
end
end
demo name: "demo" # "Name: demo."
demo name: "demo", label: "Demo" # "Name: demo, Label: Demo."
demo # "No attributes found."
demo x: 1, y: 2 # "Unable to match: {:x=>1, :y=>2}."