module GodObject::FilePermissions::ModeMixin
Common functionality of both Mode
and SpecialMode
Public Class Methods
Hook for automatic inclusion of the ClassMethods
mixin @private
# File lib/god_object/file_permissions/mode_mixin.rb, line 28 def self.included(base) base.extend ClassMethods end
Public Instance Methods
@param [GodObject::FilePermissions::ModeMixin, Array<Symbol>] other
another Mode
@return [GodObject::FilePermissions::ModeMixin] a new Mode
with the
enabled digits of the current and other
# File lib/god_object/file_permissions/mode_mixin.rb, line 74 def +(other) other = other.enabled_digits if other.respond_to?(:enabled_digits) self.class.new(enabled_digits + other) end
Compares the Mode
to another to determine its relative position.
Relative position is defined by comparing the Integer representation.
@note Only other Modes or Integer-likes are considered comparable.
@param [Object] other other Object to be compared
object
@return [-1, 0, 1, nil] -1 if other is greater, 0 if other is equal and
1 if other is lesser than self, nil if comparison is impossible
# File lib/god_object/file_permissions/mode_mixin.rb, line 138 def <=>(other) to_i <=> other.to_i rescue NoMethodError nil end
@param [GodObject::FilePermissions::ModeMixin, Array<Symbol>] other
another Mode
@return [GodObject::FilePermissions::ModeMixin] a new Mode
with the
enabled digits of the current without the enabled digits of other
# File lib/god_object/file_permissions/mode_mixin.rb, line 96 def difference(other) other = other.enabled_digits if other.respond_to?(:enabled_digits) self.class.new(enabled_digits - other) end
Answers if another object is equal and of the same type family.
@see GodObject::FilePermissions::ModeMixin
#<=> @param [Object] other an object to be checked for equality @return [true, false] true if the object is considered equal and of the
same type family, false otherwise
# File lib/god_object/file_permissions/mode_mixin.rb, line 150 def eql?(other) self == other && other.kind_of?(self.class) end
Represents a Mode
as String for debugging.
@return [String] a String representation for debugging
# File lib/god_object/file_permissions/mode_mixin.rb, line 157 def inspect "#<#{self.class}: #{to_s.inspect}>" end
@param [GodObject::FilePermissions::ModeMixin, Integer] other another
Mode
@return [GodObject::FilePermissions::ModeMixin] a new Mode
with only
those digits enabled which are enabled in both the current and other
# File lib/god_object/file_permissions/mode_mixin.rb, line 108 def intersection(other) other = other.to_i if other.respond_to?(:to_i) self.class.new(to_i & other) end
@return [GodObject::FilePermissions::ModeMixin] a new Mode
with all
digit states inverted
# File lib/god_object/file_permissions/mode_mixin.rb, line 66 def invert self.class.new(disabled_digits) end
@param [GodObject::FilePermissions::ModeMixin, Integer] other another
Mode
@return [GodObject::FilePermissions::ModeMixin] a new Mode
with the
enabled digits which are enabled in only one of current and other
# File lib/god_object/file_permissions/mode_mixin.rb, line 120 def symmetric_difference(other) other = other.to_i if other.respond_to?(:to_i) self.class.new(to_i ^ other) end
@param [GodObject::FilePermissions::ModeMixin, Integer] other another
Mode
@return [GodObject::FilePermissions::ModeMixin] a new Mode
with the
enabled digits of the current and other
# File lib/god_object/file_permissions/mode_mixin.rb, line 84 def union(other) other = other.to_i if other.respond_to?(:to_i) self.class.new(to_i | other) end