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

When class method deal with class variable , variable can not hold value. #3539

Closed
keizo042 opened this Issue Mar 24, 2017 · 1 comment

Comments

Projects
None yet
1 participant
@keizo042
Contributor

keizo042 commented Mar 24, 2017

hello dev,
I would like to ask dev whether the behavior is correct or not.

in cv.rb

class Greeding
  @@text = nil
  class << self
    def text=(word)
      @@text = word
    end
  end

  def text
    @@text
  end
end

Greeding.text= "hello world"
puts Greeding.new.text

result

bash-3.2$ ./mruby/bin/mruby ./cv.rb

bash-3.2$ ruby ./cv.rb
hello world

I expect Greeding#text return "hello world".
as follow code, it behaves the same way on MRI and mruby

class Greeding
  @@text = nil
    def self.text=(word)
      @@text = word
    end

  def text
    @@text
  end
end

Greeding.text= "hello world"
puts Greeding.new.text

Env

  • Darwin XXXX 16.4.0 Darwin Kernel Version 16.4.0: Thu Dec 22 22:53:21 PST 2016; root:xnu-3789.41.3~3/RELEASE_X86_64 x86_64
  • mruby commit id 051e40c
  • ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16]
@keizo042

This comment has been minimized.

Show comment
Hide comment
@keizo042

keizo042 Mar 27, 2017

Contributor

FYI, mruby-1.1.0 work the some way as MRI. but mruby-1.2.0 does not.

Contributor

keizo042 commented Mar 27, 2017

FYI, mruby-1.1.0 work the some way as MRI. but mruby-1.2.0 does not.

keizo042 added a commit to keizo042/mruby that referenced this issue Mar 30, 2017

keizo042 added a commit to keizo042/mruby that referenced this issue Mar 30, 2017

keizo042 added a commit to keizo042/mruby that referenced this issue Mar 30, 2017

keizo042 added a commit to keizo042/mruby that referenced this issue Mar 30, 2017

@matz matz closed this in 5efe77f Mar 30, 2017

matz added a commit that referenced this issue Mar 30, 2017

Merge pull request #3570 from keizo042/fix_cv_definition_in_singleton
Modify class variable definition in singleton class; fix #3539

matz added a commit that referenced this issue Apr 10, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment