Sha256: 45d24e763e49998358c584358b7387b3265c4b372777da0fbce1f0c5b7247aad

Contents?: true

Size: 505 Bytes

Versions: 10

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(:a, :b)} do
    calcm(a) + calcm(b)
  end
  func(:calcm).seems as {mul(:a, :b)} do
    calcm(a) * calcm(b)
  end
  func(:calcm).seems as {:value} do
    value
  end
end

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
patternmatching-0.1.4 examples/partial_style_method.rb
patternmatching-0.1.2 examples/partial_style_method.rb
patternmatching-0.1.3 examples/partial_style_method.rb
patternmatching-0.2.0 examples/partial_style_method.rb
patternmatching-0.2.2 examples/partial_style_method.rb
patternmatching-0.2.3 examples/partial_style_method.rb
patternmatching-0.2.5 examples/partial_style_method.rb
patternmatching-0.1.1 examples/partial_style_method.rb
patternmatching-0.2.1 examples/partial_style_method.rb
patternmatching-0.2.4 examples/partial_style_method.rb