Sha256: 38c6d37ea76b2108a7201c10017c51d101ac80f34289481404706ac053db1819
Contents?: true
Size: 1.24 KB
Versions: 18
Compression:
Stored size: 1.24 KB
Contents
# frozen_string_literal: true module Bridgetown module Prioritizable module ClassMethods # @!method priorities # @return [Hash<Symbol, Object>] # Get or set the priority of this class. When called without an # argument it returns the priority. When an argument is given, it will # set the priority. # # @param priority [Symbol] new priority (optional) # Valid options are: `:lowest`, `:low`, `:normal`, `:high`, `:highest` # @return [Symbol] def priority(priority = nil) @priority ||= nil @priority = priority if priority && priorities.key?(priority) @priority || :normal end # Spaceship is priority [higher -> lower] # # @param other [Class] The class to be compared. # @return [Integer] -1, 0, 1. def <=>(other) priorities[other.priority] <=> priorities[priority] end end def self.included(klass) klass.extend ClassMethods klass.class_attribute :priorities, instance_accessor: false end # Spaceship is priority [higher -> lower] # # @param other [object] The object to be compared. # @return [Integer] -1, 0, 1. def <=>(other) self.class <=> other.class end end end
Version data entries
18 entries across 18 versions & 1 rubygems