summaryrefslogtreecommitdiff
path: root/spec/ruby/core/method/fixtures/classes.rb
blob: f3b7ff921cf27b2e246608b61bae624030e2a128 (plain)
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
module MethodSpecs


  class SourceLocation
    def self.location # This needs to be on this line
      :location       # for the spec to pass
    end

    def self.redefined
      :first
    end

    def self.redefined
      :last
    end

    def original
    end

    alias :aka :original
  end

  class Methods
    def foo
      true
    end

    alias bar foo
    alias baz bar

    def same_as_foo
      true
    end

    def respond_to_missing? method, bool
      [:handled_via_method_missing, :also_handled].include? method
    end

    def method_missing(method, *arguments)
      if [:handled_via_method_missing, :also_handled].include? method
        arguments
      else
        super
      end
    end

    attr_accessor :attr

    def zero; end
    def one_req(a); end
    def two_req(a, b); end

    def zero_with_block(&blk); end
    def one_req_with_block(a, &blk); end
    def two_req_with_block(a, b, &blk); end

    def one_opt(a=nil); end
    def one_req_one_opt(a, b=nil); end
    def one_req_two_opt(a, b=nil, c=nil); end
    def two_req_one_opt(a, b, c=nil); end

    def one_opt_with_block(a=nil, &blk); end
    def one_req_one_opt_with_block(a, b=nil, &blk); end
    def one_req_two_opt_with_block(a, b=nil, c=nil, &blk); end
    def two_req_one_opt_with_block(a, b, c=nil, &blk); end

    def zero_with_splat(*a); end
    def one_req_with_splat(a, *b); end
    def two_req_with_splat(a, b, *c); end
    def one_req_one_opt_with_splat(a, b=nil, *c); end
    def two_req_one_opt_with_splat(a, b, c=nil, *d); end
    def one_req_two_opt_with_splat(a, b=nil, c=nil, *d); end

    def zero_with_splat_and_block(*a, &blk); end
    def one_req_with_splat_and_block(a, *b, &blk); end
    def two_req_with_splat_and_block(a, b, *c, &blk); end
    def one_req_one_opt_with_splat_and_block(a, b=nil, *c, &blk); end
    def two_req_one_opt_with_splat_and_block(a, b, c=nil, *d, &blk); end
    def one_req_two_opt_with_splat_and_block(a, b=nil, c=nil, *d, &blk); end

    define_method(:zero_defined_method, Proc.new {||})
    define_method(:zero_with_splat_defined_method, Proc.new {|*x|})
    define_method(:one_req_defined_method, Proc.new {|x|})
    define_method(:two_req_defined_method, Proc.new {|x, y|})
    define_method(:no_args_defined_method) {}
    define_method(:two_grouped_defined_method) {|(_x1,_x2)|}

    attr_reader :reader
    attr_writer :writer
  end

  module MyMod
    def bar; :bar; end
  end

  class MySuper
    include MyMod
  end

  class MySub < MySuper; end

  class A
    def baz(a, b)
      self.class
    end
    def overridden; end
  end

  class B < A
    def overridden; end
  end

  module BetweenBAndC
    def overridden; end
  end

  class C < B
    include BetweenBAndC
    def overridden; end
  end

  module OverrideAgain
    def overridden; end
  end

  class D
    def bar() 'done' end
  end

  class Eql

    def same_body
      1 + 1
    end

    alias :same_body_alias :same_body

    def same_body_with_args(arg)
      1 + 1
    end

    def different_body
      1 + 2
    end

    def same_body_two
      1 + 1
    end

    private
    def same_body_private
      1 + 1
    end
  end

  class Eql2

    def same_body
      1 + 1
    end

  end

  class ToProc
    def method_called(a, b)
      ScratchPad << [a, b]
    end

    def to_proc
      method(:method_called).to_proc
    end
  end

  class ToProcBeta
    def method_called(a)
      ScratchPad << a
      a
    end

    def to_proc
      method(:method_called).to_proc
    end
  end

  class Composition
    def upcase(s)
      s.upcase
    end

    def succ(s)
      s.succ
    end

    def pow_2(n)
      n * n
    end

    def double(n)
      n + n
    end

    def inc(n)
      n + 1
    end

    def mul(n, m)
      n * m
    end
  end
end