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

Pattern matching in class method requires include instead of extend #174

Open
DawidJanczak opened this issue Oct 4, 2023 · 0 comments
Open

Comments

@DawidJanczak
Copy link

Describe the bug

When pattern matching inside a class method an include Dry::Monads[:maybe] is needed, the extend Dry::Monads[:maybe] is not enough and causes a crash.

To Reproduce

Simple script:

class Foo
  include Dry::Monads[:maybe]
  extend Dry::Monads[:maybe]

  def self.foo
    case Some(4)
    in Some(a)
      puts a
    in None()
      puts 'none'
    end
  end
end

Removing any include or extend will cause this script to fail:

  1. Removing extend causes Some(4) to raise NoMethodError: undefined method Some' for Foo:Class` (makes sense)
  2. Removing extend causes Some(a) to raise NameError: uninitialized constant Foo::Some (?)

Expected behavior

Ideally I'd like to only have to extend Dry::Monads[:maybe] for a class method, not both.

My environment

  • Affects my production application: NO
  • Ruby version: 3.1.4p223
  • OS: Docker (Alpine)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant