Project

General

Profile

Actions

Bug #17096

closed

attr_accessor doesnt work

Bug #17096: attr_accessor doesnt work

Added by mpavel (pavel m) over 5 years ago. Updated over 5 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin17]
[ruby-core:99413]

Description

its copy of incorrectly closed https://bugs.ruby-lang.org/issues/17093

require 'rubygems' class A def initialize(type:) @type = type end def b p type p type.nil? type = 'default' if type.nil? type end private attr_accessor :type end RSpec.describe A do let(:type) { 'whoaaa' } it 'return default' do expect(A.new(type: type).b).to eq('default') end it 'instance variable is "whoaaa"' do expect(A.new(type: type).instance_variable_get(:@type)).to eq(type) end end all tests green output A "whoaaa" false return default instance variable is "whoaaa" 

have a look on method b, "p type.nil?" prints false, but next line type = 'default' will run


Related issues 1 (0 open1 closed)

Updated by nobu (Nobuyoshi Nakada) over 5 years ago Actions #1

  • Is duplicate of Bug #17093: attr_accessor works strange added

Updated by nobu (Nobuyoshi Nakada) over 5 years ago Actions #2 [ruby-core:99415]

  • Status changed from Open to Rejected

type before and after type = are different things in Ruby.

Actions

Also available in: PDF Atom