Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some thoughts #3

Open
JoshCheek opened this issue Jan 18, 2021 · 0 comments
Open

Some thoughts #3

JoshCheek opened this issue Jan 18, 2021 · 0 comments

Comments

@JoshCheek
Copy link

  • In spec/spec_helper.rb maybe add $VERBOSE = nil so you aren't spammed with warnings
  • In general, you can make the syntax a lot terser like this:
    -        value =
    -          case Dio.attribute(alice)
    -          in { name: /^A/, age: 30..50 }
    -            true
    -          else
    -            false
    -          end
    -
    +        value = (Dio.attribute(alice) in { name: /^A/, age: 30..50 })
  • Ultimately this is going to hit an issue where, wanting to match things with #=== are going to create problems. I looked through the C code, and there isn't a way to interject between them. Eg consider p((Dio.dynamic(1) in { succ: { succ: { succ: Integer } } })), for that Integer to match, it requires that Dio[3].deconstruct_keys([:succ]) returns {succ: 4}, where 4 is an integer, and not a Dio::Forwarders::BaseForwarder, because it will not delegate the class lookup, thus it will not consider the wrapped integer to be an integer:
    image
  • And you can't extend such objects b/c you can't extend integers
  • And you can't refine them, b/c the Ruby C code doing the pattern matching won't see the refinement
  • So you can only actually implement it with a monkey patch:
    image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant