Sha256: ea4ba0ddf32aa2c774345e771a30077fd70476550a0dffdeb83cee916404f1bc

Contents?: true

Size: 875 Bytes

Versions: 1

Compression:

Stored size: 875 Bytes

Contents

require "heresy/version"

class Object
  class << self
    def public(*args)
      super(*normalize_args(*args))
    end

    def private(*args)
      super(*normalize_args(*args))
    end

    def protected(*args)
      super(*normalize_args(*args))
    end

    def normalize_args(*args)
      # Allow passing in an Array of method names.
      args = args.first if args.length == 1 && args.first.is_a?(Array)

      args
    end

    # +accessor+, +reader+, and +writer+ are equivalent to +attr_accessor+,
    # +attr_reader+, and +attr_writer+, except they return the arguments passed
    # to them, allowing chaining with public, private, and protected.

    def accessor(*args)
      attr_accessor(*args)
      args
    end

    def reader(*args)
      attr_reader(*args)
      args
    end

    def writer(*args)
      attr_writer(*args)
      args
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
heresy-5.0.0 lib/heresy/scoped_accessors.rb