summaryrefslogtreecommitdiff
path: root/spec/ruby/core/data/fixtures/classes.rb
blob: 650c0b2a623fdd4a76599ecb4b1bd755487ff234 (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
module DataSpecs
  if Data.respond_to?(:define)
    Measure = Data.define(:amount, :unit)

    class MeasureWithOverriddenName < Measure
      def self.name
        "A"
      end
    end

    class DataSubclass < Data; end

    MeasureSubclass = Class.new(Measure) do
      def initialize(amount:, unit:)
        super
      end
    end

    Empty = Data.define()

    DataWithOverriddenInitialize = Data.define(:amount, :unit) do
      def initialize(*rest, **kw)
        super
        ScratchPad.record [:initialize, rest, kw]
      end
    end

    Area = Data.define(:width, :height, :area) do
      def initialize(width:, height:)
        super(width: width, height: height, area: width * height)
      end
    end
  end
end