Skip to content

wintonpc/destruct

Folders and files

NameName
Last commit message
Last commit date

Latest commit

539c714 · Apr 16, 2019
Apr 15, 2019
Apr 16, 2019
Apr 16, 2019
Apr 15, 2019
Aug 31, 2018
Sep 2, 2018
Sep 11, 2018
Aug 31, 2018
Apr 15, 2019
Aug 31, 2018
Apr 16, 2019
Apr 15, 2019
Nov 5, 2013
Apr 15, 2019
Oct 23, 2013

Repository files navigation

destruct

Destructuring assignment in Ruby

General REPL usage:

# bundle exec irb
>> require 'destruct_repl'
=> true
>> p([1, Var.new(:x)]).match([1, 2])
=> #<Env: x=2>
>> transform(ast { [1, x] }).match([1, 2])
=> #<Env: x=2>

Show code:

cpat = compile([1, Var.new(:x)])
cpat.show_code

Show transformations:

$show_transformations = true
transform(ast { [1, v, 3 | 4] })
  • types.rb - pattern matchers
  • standard_pattern.rb - invented syntax for pattern matchers
  • destruct_spec.rb - example case/when usage.

If you get a "No method 'eval' on NilClass" error or "binding must be provided" error, pass binding to any methods that take it as an optional parameter:

Point = Struct.new(:x, :y)
transform(ast { Point[x: 1, y: v] }, binding)

About

Destructuring assignment in Ruby

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published