Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 149 lines (133 sloc) 1.994 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 144 145 146 147 148 149
assert '42', "FOO=42; p FOO"
assert '42', "FOO=42; p Object::FOO"
assert '42', "class X; FOO=42; end; p X::FOO"
assert '42', "class X; end; X::FOO=42; p X::FOO"

assert ':ok', %q{
class X; FOO=123; end
begin
p FOO
rescue NameError
p :ok
end
}

assert '42', "class X; FOO=42; def foo; FOO; end; end; p X.new.foo"
assert '42', %q{
FOO=123
class X; FOO=42; end
class Y < X; def foo; FOO; end; end
p Y.new.foo
}

assert '42', "FOO=42; 1.times { p FOO }"
assert '42', %q{
module X
FOO=42
1.times { p FOO }
end
}

assert '42', %q{
class X
FOO = 42
class Y; def foo; FOO; end; end
end
p X::Y.new.foo
}

assert '42', %q{
class X; FOO = 42; end
class Y < X; def foo; FOO; end; end
p Y.new.foo
}

assert '42', %q{
class X; FOO = 123; end
class Z
FOO = 42
class Y < X; def foo; FOO; end; end
end
p Z::Y.new.foo
}

assert '42', %q{
class A
module B
def foo
42
end
end
module C
extend B
end
end
p A::C.foo
}

assert 'true', 'p ::String == String'

assert '42', %q{
o = Object.new
class << o
module Foo
Bar = 42
end
class Baz; include Foo; end
class Baz;
def self.bar; Bar; end
end
def baz; Baz; end
end
p o.baz.bar
}

assert '42', %q{
module M
FOO = 42
class X
class << self; p FOO; end
end
end
}

assert '1', "class Float; class X; p ROUNDS; end; end"

assert '42', %{
class A
B = 42
end
A.class_eval {
def bar
p B
end
}
A.new.bar
}

assert ':ok', %{
module M
FOO=42
end
class M::Foo
begin
p FOO
rescue NameError
p :ok
end
end
}

assert '42', %{
class Foo
FOO=42
def hey
Object.new.instance_eval { p FOO }
end
end
Foo.new.hey
}

assert '42', %{
module Foo; end
module Foo::Bar
FOO=42
class X
p FOO
end
end
}

assert '42', %{
module M
FOO=42
class C; end
class C::C2
p FOO
end
end
}
Something went wrong with that request. Please try again.