#549: Class variables are not initialised properly. -------------------------------------+-------------------------------------- Reporter: sorin.ionescu@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: MacRuby 0.5 Component: MacRuby | Keywords: class, instance -------------------------------------+-------------------------------------- Description changed by martinlagardette@…: Old description:
The mime-types gem has a class and an instance interface. The class interface uses an instance of itself. However, it doesn’t work in MacRuby. It does not seem to be initialised properly. I have included in a sample code with the expected behaviour. Changing `@__types__` to `@@__types__` will not fix it.
{{{ #!/usr/bin/env macruby
class Test def initialize() @foo = true end
def add(something) puts "Is foo nil: #{@foo.nil?}" end
@__types__ = self.new()
def self.add(something) @__types__.add(something) end end
t = Test.new t.add(3) Test.add(4) }}}
Output (MacRuby 0.5) {{{ Is foo nil: false Is foo nil: true }}} Expected (Ruby 1.9.1/1.8.7) {{{ Is foo nil: false Is foo nil: false }}}
New description: The mime-types gem has a class and an instance interface. The class interface uses an instance of itself. However, it doesn’t work in MacRuby. It does not seem to be initialised properly. I have included in a sample code with the expected behaviour. Changing `@__types__` to `@@__types__` will not fix it. {{{ class MacRubyInitTest def initialize @foo = true end def add p self puts "@foo = " + @foo.inspect end @__types__ = self.new() def self.add @__types__.add end end t = MacRubyInitTest.new t.add MacRubyInitTest.add }}} Output (MacRuby 0.5) {{{ <MacRubyInitTest:0x200024d80 @foo=true> @foo = true <MacRubyInitTest:0x200024e00 @foo=true> @foo = nil }}} Expected (Ruby 1.9.1/1.8.7) {{{ #<MacRubyInitTest:0x00000100847920 @foo=true> @foo = true #<MacRubyInitTest:0x00000100847a70 @foo=true> @foo = true }}} -- -- Ticket URL: <http://www.macruby.org/trac/ticket/549#comment:4> MacRuby <http://macruby.org/>