-
Notifications
You must be signed in to change notification settings - Fork 127
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
Improve variable type name request #957
Conversation
|
||
begin | ||
klass.name || klass.to_s | ||
rescue Exception => e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does it drop klass.to_s
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe type_name
is already a String so I don't think to_s
is necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. klass.name
can return nil
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh, I see. Thanks for the catch!
I updated the code to use to_s
and added a test for anonymous class instances to ensure the type
is ""
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you really need nil
for the name?
Previous one is klass.name || klass.to_s
but your code uses klass.name.to_s
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous code means that if klass.name
is given, use it, otherwise use klass.to_s
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the code so that the type
is set to klass.to_s
if there is no type name and I updated the related test (test_anonymous_class_instance
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, the error because of to_s
is ignored.
I'll fix it after merging.
d59e3ca
to
a136d09
Compare
a136d09
to
b83389a
Compare
Description
It is possible to override the
name
method in a class with a method that has arguments, resulting in anArgumentError
when callingklass.name
. #790 addresses this by handing the exception and setting the variable'stype
to"<Error: #{e.message} (#{e.backtrace.first}>"
.This PR improves the handling of the case where the
class
method is overwritten and removes the need for thetype_name
method by usingM_NAME.bind_call(klass)
instead of calling thename
method. Instead of the variable's type being the error message, it is now more accurate:Before
After
(This example is from the test included in this PR)