[ruby-core:112668] Impossible to pattern-match against the return value of a method

2 Mar
2023
2 Mar
'23
1:02 p.m.
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?
885
Age (days ago)
885
Last active (days ago)
0 comments
1 participants
participants (1)
-
chowlett09@gmail.com