[#115884] Windows Ruby 3.2.2: Non-English character added to Windows Registry String Value — Jay Mav via ruby-core <ruby-core@...>
Hello,
3 messages
2023/12/24
[ruby-core:115735] [Ruby master Bug#20063] Inconsistent behavior with required vs optional parameters
From:
"rubyFeedback (robert heiler) via ruby-core" <ruby-core@...>
Date:
2023-12-13 20:36:12 UTC
List:
ruby-core #115735
Issue #20063 has been updated by rubyFeedback (robert heiler).
That last example is one very complicated def - it is probably
the most complicated one I have seen so far.
In regards to jemmai's example: what would you expect to be the
correct behaviour? I have not seen methods defined with the
same arguments (such as "(_a = 1, _a = 2)"). Do such examples
come up in real code? Is that behaviour documented or specified?
I guess the example can be generalized to using the same name
in the method definition, but then I tried it myself, thinking
this is equivalent to this:
def foobar_optional(x = 1, x = 2)
x
end
Then I realised it is not:
duplicated argument name (SyntaxError)
So now I wonder about the use case and behaviour of _ variables.
Why isn't this a SyntaxError?
----------------------------------------
Bug #20063: Inconsistent behavior with required vs optional parameters
https://bugs.ruby-lang.org/issues/20063#change-105668
* Author: jemmai (Jemma Issroff)
* Status: Open
* Priority: Normal
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
Using repeated anonymous parameters, gives different behavior with the parameters in the same order based on whether they are required or optional.
```
def example_with_optional(_a = 1, _a = 2)
_a
end
def example_with_required(_a, _a)
_a
end
p example_with_optional # 2
p example_with_required(1, 2) # 1
```
It is unexpected that these two methods would return differently given the parameters are in the same order, based on whether they are optional or required.
--
https://bugs.ruby-lang.org/
______________________________________________
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/