Sha256: 7a7b21694c954f8f4ce5dd17d665182fad6f114a6d7c39a8888e4404881845c4

Contents?: true

Size: 505 Bytes

Versions: 1

Compression:

Stored size: 505 Bytes

Contents

require "patternmatching"

# Structured data builder 
code = PatternMatching.build {plus(mul(100, 100), 200)}

# Partial style method example
class Calc
  # At first, extends with the module
  extend PatternMatching
  
  # def calcm(o), as 3 partial styles
  func(:calcm).seems as {plus(:x, :y)} do
    calcm(x) + calcm(y)
  end
  func(:calcm).seems as {mul(:x, :y)} do
    calcm(x) * calcm(y)
  end
  func(:calcm).seems as {:value} do
    value
  end
end

# use as standard method
p Calc.new.calcm(code)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
patternmatching-0.1.0 examples/partial_style_method.rb