File: flags.rb

package info (click to toggle)
dlr-languages 20090805%2Bgit.e6b28d27%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 51,484 kB
  • ctags: 59,257
  • sloc: cs: 298,829; ruby: 159,643; xml: 19,872; python: 2,820; yacc: 1,960; makefile: 96; sh: 65
file content (290 lines) | stat: -rw-r--r-- 5,187 bytes parent folder | download
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
class Module
  public :private, :public, :module_function
end

module M
end

class C
  def foo
    1.times {
      M.private
  
      def pri1
      end
    }
  
    def pubXpri2             # private in 1.9, public in 1.8 (!) 
    end
  end
  
  new.foo

  def pub3
  end
end

p C.public_instance_methods(false).sort
p C.private_instance_methods(false).sort
puts '--'

class D
  1.times {
    private
    
    def pri1
    end
  }
  
  def pubXpri2               # private in 1.9, public in 1.8 (!) 
  end
end

p D.public_instance_methods(false).sort
p D.private_instance_methods(false).sort
puts '--'

class F1
  module_eval {
    private
    
    def pri1
    end
  }
  
  def pub2               # public in 1.8 and 1.9, ok
  end
end

p F1.public_instance_methods(false).sort
p F1.private_instance_methods(false).sort

puts '--'

class F2
  define_method(:foo) {
    M.private
    
    def pri1
    end
  }
  
  new.foo
  
  def pubXpri2               # public in 1.8, private in 1.9 (!)
  end
end

p F2.public_instance_methods(false).sort
p F2.private_instance_methods(false).sort

puts '--- module_function ---'
puts '- G -'

class G
  1.times {
    M.module_function
    
    def mf1
    end
  }
  
  def iXmf2                # mf in 1.9, instance in 1.8 (!)             
  end
rescue
  puts $!
end

p G.singleton_methods(false).sort
p G.private_instance_methods(false).sort
p G.public_instance_methods(false).sort
puts '- H -'

class H
  module_eval {
    M.module_function
    
    def mf1
    end
  }
  
  def i2               
  end
rescue
  puts $!
end

p H.singleton_methods(false).sort
p H.private_instance_methods(false).sort
p H.public_instance_methods(false).sort

puts '- I -'

class I
  define_method(:bar) {
    M.module_function
    
    def mf1
    end
  }
  
  new.bar
  
  def iXmf2                      # instance in 1.8, mf in 1.9 (!) 
  end
rescue
  puts $!
end

p I.singleton_methods(false).sort
p I.private_instance_methods(false).sort
p I.public_instance_methods(false).sort

puts '------ flag inheritance ----'
puts '- J -'
class J
  private
  1.times {                        # inherits
    1.times {                      # inherits
      def pri
      end
    }
  }
end

p J.public_instance_methods(false).sort
p J.private_instance_methods(false).sort

puts '- K -'
class K
  private
  module_eval {                    # doesn't inherit
    def pub1
    end
      
    private
    define_method(:priXpub1) {         # inherits (!); 
      def priXpub2                 # 1.9: public (!)
      end
      
      M.private
      class X                      # doesn't inherit
        def pub3
        end
      end
    }
  }
  
  new.send :priXpub1
end

p K.public_instance_methods(false).sort
p K.private_instance_methods(false).sort
p K::X.public_instance_methods(false).sort
p K::X.private_instance_methods(false).sort

puts '- L (1.9 bad visibility) -'
module L
  module_function
  
  1.times {                        
    1.times {                      
      def mf
      end
    }
  }
end

p L.public_instance_methods(false).sort
p L.private_instance_methods(false).sort
p L.singleton_methods(false).sort

puts '- N -'
module N
  private  
  module_function                      # overrides visibility to public
  
  module_eval {                        # doesn't inherit
    def mf
    end    
  }
end

p N.public_instance_methods(false).sort
p N.private_instance_methods(false).sort
p N.singleton_methods(false).sort

puts '- O (1.8 and 1.9 bugs), -'
module O
  module_function
  
  # 1.8: foo private, not mf (!)
  # 1.9: foo public, not mf
  define_method(:priXpub1) {                  # inherits 1.9 (!)
  
    # 1.8: defines O_C::mf, S(O_C)::mf  (!)
    # 1.9: defines O::mf, S(O)::mf
    def mf                              
    end    
  }
  
end
  
class O_C
  include O
  new.send :priXpub1
end

p O.public_instance_methods(false).sort
p O.private_instance_methods(false).sort
p O.singleton_methods(false).sort
p O_C.public_instance_methods(false).sort
p O_C.private_instance_methods(false).sort
p O_C.singleton_methods(false).sort

puts '- P -'
class P
  protected
    
  module_eval {               
    def pub1; end             # looks for the inner-most module/(real (!) method) scope
    private                   
    def pri2; end             
  }
  
  define_method(:priXpub0) {               
    def pro3; end             # looks for the inner-most module/(real (!) method) scope
    M.private                   
    def pri4; end             
  }
  
  new.send :priXpub0
  
  def self.bar
    private
  
    module_eval {               
      def pub5; end             # looks for the inner-most module/(real (!) method) scope
      public
      def pub6; end             
    }
  
    define_method(:priXpub10) {               
      def pri7; end             # looks for the inner-most module/(real (!) method) scope
      M.public                  
      def pub8; end             
    }
    
    new.send :priXpub10
    
    def priXpub9; end           # 1.8: pri, 1.9: pub (!)
  end
  
  bar
  
end

p P.public_instance_methods(false).sort
p P.private_instance_methods(false).sort
p P.protected_instance_methods(false).sort