Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 144 lines (131 sloc) 2.315 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
assert "nil", "p @foo"

assert "42", %q{
class Foo
def initialize; @x = 42; end;
def x; @x; end
end
p Foo.new.x
}

assert "42", %q{
class Foo
def initialize; @x, @y = 40, 2; end
end
class Foo
def z; @z ||= @x + @y; end
end
p Foo.new.z
}

assert "42", %q{
class Foo
def initialize; @x = 42; end
end
o = Foo.new
class Foo
def y; @y ||= @x; end
end
p o.y
}

assert "42", %q{
instance_variable_set(:@foo, 42)
p instance_variable_get(:@foo)
}

assert "42", %q{
class Foo
def initialize; @x = 42; end
end
o = Foo.new
p o.instance_variable_get(:@x)
}

assert "42\n123", %q{
class Foo
@foo = 42
def self.foo; @foo; end
def self.foo=(x); @foo=x; end
end
p Foo.foo
Foo.foo=123
p Foo.foo
}

assert '231', %q{
class Foo
def initialize
@v1 = 1; @v2 = 2; @v3 = 3
@v4 = 4; @v5 = 5; @v6 = 6
@v7 = 7; @v8 = 8; @v9 = 9
@v10 = 10; @v11 = 11; @v12 = 12
@v13 = 13; @v14 = 14; @v15 = 15
@v16 = 16; @v17 = 17; @v18 = 18
@v19 = 19; @v20 = 20; @v21 = 21
end
def foo
@v1 + @v2 + @v3 + @v4 + @v5 + @v6 +
@v7 + @v8 + @v9 + @v10 + @v11 + @v12 +
@v13 + @v14 + @v15 + @v16 + @v17 + @v18 +
@v19 + @v20 + @v21
end
end
p Foo.new.foo
}

assert '42', %{
class Foo < File::Stat
def foo; @foo=42; end
end
o=Foo.new('/System')
o.foo
p o.instance_variable_get(:@foo)
}

assert 'nil', %{
class Foo
def bar
@v1 = @v2 = @v3 = @v4 = @v5 = @v6 = @v7 = @v8 = @v9 = @v10 = 0
end
def foo
p @oops
end
end
Foo.new.foo
}

assert '42', %{
class Foo
def initialize
@foo=42
end
def foo
o = Object.new
self.addObserver(o, forKeyPath:'foo', options:0, context:nil)
p @foo
end
end
Foo.new.foo
}

assert '42', %{
class Foo
def initialize
@foo=42
end
def foo
o = Object.new
self.addObserver(o, forKeyPath:'foo', options:0, context:nil)
1.times { p @foo }
end
end
Foo.new.foo
}

assert "2\n2", %{
class X; end
class Y < X
def set_foo; @foo = 1; end
end
class X
def set_bar; @bar = 2; end
def bar; @bar; end
end
class Z < Y
def set_foo; @foo = 3; end
end
o = Z.new
o.set_bar
p o.bar
o.set_foo
p o.bar
}
Something went wrong with that request. Please try again.