-
Notifications
You must be signed in to change notification settings - Fork 217
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
RFC: new Attribute#ivar
API
#2110
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -304,6 +304,21 @@ def update(name: self.name, type: self.type, ivar_name: self.ivar_name, kind: se | |
visibility: visibility | ||
) | ||
end | ||
|
||
def ivar | ||
@ivar ||= begin | ||
ivar_name = case self.ivar_name | ||
when false | ||
return nil # Skip the instance variable declaration entirely | ||
when nil | ||
:"@#{name}" # Infer the instance variable name from the attribute name | ||
else | ||
self.ivar_name # Use the custom instance variable name given by the user | ||
end | ||
|
||
InstanceVariable.new(name: ivar_name, type: type, location: location, comment: comment) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Open question: what should the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should have the Not very sure about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We still have to fill in the parameters, are you suggesting I pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, I'm sorry. I was confused. I thought the |
||
end | ||
end | ||
end | ||
|
||
class AttrReader < Base | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,6 +185,8 @@ module RBS | |
include _HashEqual | ||
|
||
def update: (?name: Symbol, ?type: Types::t, ?ivar_name: Symbol | false | nil, ?kind: kind, ?annotations: Array[Annotation], ?location: loc?, ?comment: Comment?, ?visibility: visibility?) -> instance | ||
|
||
def ivar: () -> InstanceVariable? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simple return type! :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it still make sense for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question, since there's backwards compatibility concerns there. We can add a new keyword arg (perhaps |
||
end | ||
|
||
class AttrReader < Base | ||
|
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.
Now the semantics are clear: You either get back an
InstanceVariable
object, ornil
(meaning this attribute was declared with no backing ivar declaration, e.g.attr_reader foo(): Foo
).Open question: How should we model the difference between these two?
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 difference between the two looks fine, if we consider this is a kind of utility class.
If we really need the detail of the syntax, we can use the old API.