Class: RBS::Annotate::Annotations::Copy
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/rbs/annotate/annotations.rb |
Class Method Summary
- .new(annotation:, source:) ⇒ Copy constructor
Instance Attribute Summary
- #annotation readonly
- #singleton? ⇒ Boolean readonly
- #source readonly
Instance Method Summary
- #==(other) (also: #eql?)
-
#eql?(other)
Alias for #==.
- #hash
- #method_name
- #partition
- #type_name
Constructor Details
.new(annotation:, source:) ⇒ Copy
# File 'lib/rbs/annotate/annotations.rb', line 54
def initialize(annotation:, source:) @annotation = annotation @source = source end
Instance Attribute Details
#annotation (readonly)
[ GitHub ]# File 'lib/rbs/annotate/annotations.rb', line 52
attr_reader :annotation, :source
#singleton? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/rbs/annotate/annotations.rb', line 71
def singleton? _, m = partition if m m[0] else false end end
#source (readonly)
[ GitHub ]# File 'lib/rbs/annotate/annotations.rb', line 52
attr_reader :annotation, :source
Instance Method Details
#==(other) Also known as: #eql?
[ GitHub ]# File 'lib/rbs/annotate/annotations.rb', line 84
def ==(other) other.is_a?(Copy) && other.annotation == annotation && other.source == source end
#eql?(other)
Alias for #==.
# File 'lib/rbs/annotate/annotations.rb', line 90
alias eql? ==
#hash
[ GitHub ]# File 'lib/rbs/annotate/annotations.rb', line 80
def hash self.class.hash ^ annotation.hash ^ source.hash end
#method_name
[ GitHub ]# File 'lib/rbs/annotate/annotations.rb', line 64
def method_name _, m = partition if m m[1] end end
#partition
[ GitHub ]# File 'lib/rbs/annotate/annotations.rb', line 92
def partition case when match = source.match(/(?<constant_name>[^#])#(?<method_name>.)/) [ TypeName(match[:constant_name] || raise), [ false, (match[:method_name] or raise).to_sym ] ] when match = source.match(/(?<constant_name>[^#])\.(?<method_name>.)/) [ TypeName(match[:constant_name] || raise), [ true, (match[:method_name] or raise).to_sym ] ] else [ TypeName(source), nil ] end end
#type_name
[ GitHub ]# File 'lib/rbs/annotate/annotations.rb', line 59
def type_name name, _ = partition name end