ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:99413] [Ruby master Bug#17096] attr_accessor doesnt work
@ 2020-07-31  6:42 mpavel
  2020-07-31  8:05 ` [ruby-core:99415] " nobu
  0 siblings, 1 reply; 2+ messages in thread
From: mpavel @ 2020-07-31  6:42 UTC (permalink / raw
  To: ruby-core

Issue #17096 has been reported by mpavel (pavel m).

----------------------------------------
Bug #17096: attr_accessor doesnt work
https://bugs.ruby-lang.org/issues/17096

* Author: mpavel (pavel m)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin17]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
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



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [ruby-core:99415] [Ruby master Bug#17096] attr_accessor doesnt work
  2020-07-31  6:42 [ruby-core:99413] [Ruby master Bug#17096] attr_accessor doesnt work mpavel
@ 2020-07-31  8:05 ` nobu
  0 siblings, 0 replies; 2+ messages in thread
From: nobu @ 2020-07-31  8:05 UTC (permalink / raw
  To: ruby-core

Issue #17096 has been updated by nobu (Nobuyoshi Nakada).

Status changed from Open to Rejected

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


----------------------------------------
Bug #17096: attr_accessor doesnt work
https://bugs.ruby-lang.org/issues/17096#change-86866

* Author: mpavel (pavel m)
* Status: Rejected
* Priority: Normal
* ruby -v: ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin17]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
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



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-07-31  8:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-31  6:42 [ruby-core:99413] [Ruby master Bug#17096] attr_accessor doesnt work mpavel
2020-07-31  8:05 ` [ruby-core:99415] " nobu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).