Sha256: 8f40a3222e547b6fadd21b5a03675f575fb1cfe9bb3b0e6ab9a807981f88f090

Contents?: true

Size: 686 Bytes

Versions: 5

Compression:

Stored size: 686 Bytes

Contents

# Refinements to the Symbol class
module SymbolExtensions
  refine Symbol do
    # Converts self to a boolean if it is :allow, :abstain, :deny. Assumes that abstain means false.
    # @return [Boolean] Boolean representation of allow, abstain, or deny. Abstain means false.
    # @raise [NotImplementedError] If unsupported symbol is converted (not :allow, :abstain, :deny)
    def to_bool
      raise NotImplementedError("Cannot convert #{self} to a boolean! #to_bool only supports :allow, :abstain and :deny.") unless %i[allow abstain deny].include? self
      return true if self == :allow
      return false if self == :abstain
      return false if self == :deny
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
scram-0.1.4 lib/scram/core_ext/symbol_extensions.rb
scram-0.1.3 lib/scram/core_ext/symbol_extensions.rb
scram-0.1.2 lib/scram/core_ext/symbol_extensions.rb
scram-0.1.1 lib/scram/core_ext/symbol_extensions.rb
scram-0.1.0 lib/scram/core_ext/symbol_extensions.rb