[ruby-core:112668] Impossible to pattern-match against the return value of a method
From:
chowlett09--- via ruby-core <ruby-core@...>
Date:
2023-03-02 13:02:24 UTC
List:
ruby-core #112668
Given the following snippet: ``` def foo = "foo" def bar = "bar" text = "foo" matches = text in bar ``` The result will be "true", and bar is now a local variable with value "foo". If you instead try ``` def foo = "foo" def bar = "bar" text = "foo" matches = text in ^bar ``` You get SyntaxError: "bar: no such local variable" The only way I've found to be able to do this as a one-liner is with something like: ``` def foo = "foo" def bar = "bar" text = "foo" matches = text in ^(tmp = bar) ``` Anyone else find this behaviour a bit odd? ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/