Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/rdoc/code_object/attr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def ==(other)
# Add +an_alias+ as an attribute in +context+.

def add_alias(an_alias, context)
new_attr = self.class.new(text, an_alias.new_name, rw, comment, singleton: singleton)
access_type = an_alias.new_name.end_with?('=') ? 'W' : 'R'
new_attr = self.class.new(text, an_alias.new_name, access_type, comment, singleton: singleton)
new_attr.record_location an_alias.file
new_attr.visibility = self.visibility
new_attr.is_alias_for = self
Expand Down
14 changes: 14 additions & 0 deletions test/rdoc/code_object/attr_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,18 @@ def test_type
assert_equal 'class', @a.type
end

[
['bar', 'baz', 'R'],
['bar=', 'baz=', 'W']
].each do |original_name, new_name, expected_rw|
define_method("test_add_alias_#{new_name}_for_an_attribute_accessor") do
context = RDoc::Context.new
attr = RDoc::Attr.new nil, 'bar', 'RW', ''
an_alias = RDoc::Alias.new nil, original_name, new_name, ''

new_attr = attr.add_alias an_alias, context

assert_equal expected_rw, new_attr.rw
end
end
end