File: bool.rb

package info (click to toggle)
ruby-sassc 2.4.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 368 kB
  • sloc: ruby: 2,277; makefile: 3
file content (32 lines) | stat: -rw-r--r-- 941 bytes parent folder | download | duplicates (3)
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
27
28
29
30
31
32
# frozen_string_literal: true

# A SassScript object representing a boolean (true or false) value.

class SassC::Script::Value::Bool < SassC::Script::Value

  # The true value in SassScript.
  # This is assigned before new is overridden below so that we use the default implementation.
  TRUE = new(true)

  # The false value in SassScript.
  # This is assigned before new is overridden below so that we use the default implementation.
  FALSE = new(false)

  # We override object creation so that users of the core API
  # will not need to know that booleans are specific constants.
  # Tests `value` for truthiness and returns the TRUE or FALSE constant.
  def self.new(value)
    value ? TRUE : FALSE
  end

  # The pure Ruby value of this Boolean
  attr_reader :value
  alias_method :to_bool, :value

  # Returns the string "true" or "false" for this value
  def to_s(opts = {})
    @value.to_s
  end
  alias_method :to_sass, :to_s

end