File: attrs.rb

package info (click to toggle)
ruby-contracts 0.17-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 624 kB
  • sloc: ruby: 3,805; makefile: 4; sh: 2
file content (26 lines) | stat: -rw-r--r-- 583 bytes parent folder | download | duplicates (2)
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
# frozen_string_literal: true

module Contracts
  module Attrs
    def attr_reader_with_contract(*names, contract)
      names.each do |name|
        Contract Contracts::None => contract
        attr_reader(name)
      end
    end

    def attr_writer_with_contract(*names, contract)
      names.each do |name|
        Contract contract => contract
        attr_writer(name)
      end
    end

    def attr_accessor_with_contract(*names, contract)
      attr_reader_with_contract(*names, contract)
      attr_writer_with_contract(*names, contract)
    end
  end

  include Attrs
end