Revisions

gist: 201986 Download_button fork
public
Public Clone URL: git://gist.github.com/201986.git
Embed All Files: show embed
Text only #
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
Problem 1:
Code:
  class A; def to_ary; [1, 2, 3, 4]; end; end
  a, b, *, c = A.new
  p [a, b, c]
Arch: default
Command: jruby --1.9
Expectation: [1, 2, 4]
Output: [#<A:0x2f2295>, nil, #<A:0x2f2295>]
 
Problem 2:
Code:
  def foo; yield(1); end
  foo do |x, y = :y, z|
    p :ok if x == 1 and y == :y and z == nil
  end
Arch: default
Command: jruby --1.9
Expectation: :ok
Output:
 
Problem 3:
Code: p = proc { |x,| p x }; p.call([42])
Arch: default
Command: jruby --1.9
Expectation: 42
Output: [42]
 
Problem 4:
Code: p = proc { |x,| p x }; p.call([42,1,2,3])
Arch: default
Command: jruby --1.9
Expectation: 42
Output: [42, 1, 2, 3]
 
Problem 5:
Code:
  b = :foo.to_proc
  begin
    b.call
  rescue ArgumentError
    p :ok
  end
Arch: default
Command: jruby --1.9
Expectation: :ok
Output: ERROR CODE 1
 
Problem 6:
Code: a = [7, 8]; p case 1 when *a, *[4, 5], 1 then 1 else 2 end
Arch: default
Command: jruby --1.9
Expectation: 1
Output: ERROR CODE 1
 
Problem 7:
Code:
  class A
    B = 42
  end
  A.class_eval {
    def bar
      p B
    end
  }
  A.new.bar
Arch: default
Command: jruby --1.9
Expectation: 42
Output: ERROR CODE 1
 
Problem 8:
Code: p defined? a||=1
Arch: default
Command: jruby --1.9
Expectation: "assignment"
Output: "expression"
 
Problem 9:
Code: p defined? a&&=1
Arch: default
Command: jruby --1.9
Expectation: "assignment"
Output: "expression"
 
Problem 10:
Code: 1.times { |x| p defined? x }
Arch: default
Command: jruby --1.9
Expectation: "local-variable"
Output: "local-variable(in-block)"
 
Problem 11:
Code: p (defined? FOO && 42)
Arch: default
Command: jruby --1.9
Expectation: "expression"
Output: nil
 
Problem 12:
Code: def foo; return *[]; end; p foo
Arch: default
Command: jruby --1.9
Expectation: []
Output: nil
 
Problem 13:
Code: def f((a, b)); a end; p f([42, 53])
Arch: default
Command: jruby --1.9
Expectation: 42
Output: [42, 53]
 
Problem 14:
Code: def f((a, b)); a end; p f([42, 53, 64])
Arch: default
Command: jruby --1.9
Expectation: 42
Output: [42, 53, 64]
 
Problem 15:
Code: def f((a, b)); [a, b] end; p f([42])
Arch: default
Command: jruby --1.9
Expectation: [42, nil]
Output: [[42], nil]
 
Problem 16:
Code:
  def f((x, y, *a, b, c)); [x, y, a, b, c] end
  p f([1, 2, 3])
  p f([1, 2, 3, 4])
  p f([1, 2, 3, 4, 5])
Arch: default
Command: jruby --1.9
Expectation: [1, 2, [], 3, nil]
[1, 2, [], 3, 4]
[1, 2, [3], 4, 5]
Output: [[1, 2, 3], nil, nil, nil, nil]
[[1, 2, 3, 4], nil, nil, nil, nil]
[[1, 2, 3, 4, 5], nil, nil, nil, nil]
 
Problem 17:
Code:
  class A; def to_ary; [42]; end; end
  def f((*a)); a; end;
  p f(A.new) == [42]
Arch: default
Command: jruby --1.9
Expectation: true
Output: false
 
Problem 18:
Code: def f((*a)); a; end; o = Object.new; p f(o) == [o]
Arch: default
Command: jruby --1.9
Expectation: true
Output: false
 
Problem 19:
Code:
  class X; def foo(x); p x; end; end
  class Y < X; def foo(x); 1.times { |; x| x = 1; super; } end; end
  Y.new.foo(42)
Arch: default
Command: jruby --1.9
Expectation: 42
Output: ERROR CODE 1
 
Problem 20:
Code:
  $b = proc do p X end
  module A
   X = 42
   module_eval &$b
  end
Arch: default
Command: jruby --1.9
Expectation: 42
Output: ERROR CODE 1
 
Problem 21:
Code:
  module A
    X = 42
    class B
      def foo(&b)
        (class << self; self; end).module_eval &b
      end
    end
  end
  A::B.new.foo do p X end
Arch: default
Command: jruby --1.9
Expectation: 42
Output: ERROR CODE 1
 
Problem 22:
Code:
  f = File.open(__FILE__)
  f.ungetc("\n")
  f.ungetc("f")
  f.ungetc("de")
  f.ungetc("c")
  f.ungetc("ab")
  p f.gets.strip
Arch: default
Command: jruby --1.9
Expectation: "abcdef"
Output: ERROR CODE 1