Skip to content
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
Closed

Comments

@keizo042
Copy link
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
Copy link
Contributor Author

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 as completed in 5efe77f Mar 30, 2017
matz added a commit that referenced this issue Mar 30, 2017
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant