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

Ruby3 endless method bug #163

Open
JoshCheek opened this issue Jul 4, 2021 · 0 comments
Open

Ruby3 endless method bug #163

JoshCheek opened this issue Jul 4, 2021 · 0 comments

Comments

@JoshCheek
Copy link
Owner

The def ===(o) = inside RespondTo (works if you switch it over to an ended method)

seeing_is_believing -ge '
   module Types
     2.times do
       using Types
       private def to_type(o) = (Symbol === o ? RespondTo.new(o) : o)
       def |(type) = Or.new(to_type(self), to_type(type))
       refine(Module) { include Types }
       refine(Symbol) { include Types }
     end

     RespondTo = Struct.new(:name) {
       def ===(o) = o.respond_to?(name)
       def inspect() = ".respond_to?(#{name.inspect})"
     }.include(Types)

     Or = Struct.new(:left, :right) {
       def ===(o) left === o || right === o end
       def inspect() = "(#{left.inspect} | #{right.inspect})"
     }.include(Types)
   end

   using Types
   Integer | String | (:to_int | :to_str) # => ' -x
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