/
modulo_ambiguity1.rb
76 lines (62 loc) · 1.06 KB
/
modulo_ambiguity1.rb
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
# purpose:
# exercise constructs with modulo
#
# modulo in math data%2
# literals %(a b), %W[1 2]
#
#
#
def test(v)
p v
end
x, y = 42, 33
# -------------------------------------------
#
# Testarea for modulo
#
# -------------------------------------------
# value % value
test( 3%2 )
test( 3 % 2 )
test( 1234%(666) )
test( (1234)%666 )
# var % value
test( x%2 )
test( x%666 )
test( x%(42) )
test( x%-42-3 )
test( x%+42+3 )
# value % var
test( 666%x )
test( (42+4+2)%x )
# var % var
test( x % y )
test( x%y )
# -------------------------------------------
#
# Testarea for literals
#
# -------------------------------------------
# literal with nothing
test( %(a b c) )
test( %(1 2 (3 4)) )
test( %{TM rocks} )
# literal with 'w'
test( %W(1 2 3) )
test( %W[1 2 3] )
test( %W{1 2 3} )
test( %W<1 2 3> )
# literal with 'w' (multiline)
test(%w(a
b))
# literal with 'q'
test( %q(1 2 3) )
test( %Q(1 2 3) )
# literal with custom
test( %q"1 2 3" )
test( %q'1 2 3' )
test( %q#1 2 3# )
test( %?X.tainted? )
test( %q/1 2 3/ )
test( %q|1 2 3| )
test( %q\1 2 3\ )