Skip to content

Instantly share code, notes, and snippets.

@vincentisambart
Created October 5, 2009 08:54
Show Gist options
  • Save vincentisambart/201986 to your computer and use it in GitHub Desktop.
Save vincentisambart/201986 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment