advanced/pattern_matching.rb

tests/_examples/advanced/pattern_matching.rb in the metorex repository.

# Advanced pattern matching example
# Note: This file demonstrates Metorex-specific pattern matching extensions
# that are not part of standard Ruby syntax

value = 0
case value
when 0
  puts "Zero"
else
  puts "Not zero"
end

# Array pattern example
arr = [1, 2, 3, 4, 5]
a = arr[0]
b = arr[1]
puts "Array with first two: #{a}, #{b}"

# Object/Hash example
obj = {"x" => 10, "y" => 20}
case obj
when Hash
  x = obj["x"]
  y = obj["y"]
  puts "Object with x and y: #{x}, #{y}"
end

# Conditional example
condition = true
if condition
  puts "Wildcard with guard"
end