Class: Sass::Script::Literal
Overview
The abstract superclass for SassScript objects.
Many of these methods, especially the ones that correspond to SassScript operations, are designed to be overridden by subclasses which may change the semantics somewhat. The operations listed here are just the defaults.
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the Ruby value of the literal.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares this object with another.
-
#and(other) ⇒ Literal
The SassScript ‘and` operation.
-
#comma(other) ⇒ Script::String
The SassScript ‘,` operation (e.g. `!a, !b`, `“foo”, “bar”`).
-
#concat(other) ⇒ Script::String
The SassScript default operation (e.g. ‘!a !b`, `“foo” “bar”`).
-
#div(other) ⇒ Script::String
The SassScript ‘/` operation.
-
#eq(other) ⇒ Bool
The SassScript ‘==` operation.
-
#initialize(value = nil) ⇒ Literal
constructor
Creates a new literal.
-
#inspect ⇒ String
A readable representation of the literal.
-
#minus(other) ⇒ Script::String
The SassScript ‘-` operation.
-
#neq(other) ⇒ Bool
The SassScript ‘!=` operation.
-
#or(other) ⇒ Literal
The SassScript ‘or` operation.
-
#perform(environment) ⇒ Literal
Evaluates the literal.
-
#plus(other) ⇒ Script::String
The SassScript ‘+` operation.
-
#to_bool ⇒ Boolean
‘true` (the Ruby boolean value).
-
#to_i ⇒ Fixnum
The integer value of this literal.
-
#unary_div ⇒ Script::String
The SassScript unary ‘/` operation (e.g. `/!a`).
-
#unary_minus ⇒ Script::String
The SassScript unary ‘-` operation (e.g. `-!a`).
-
#unary_not ⇒ Bool
The SassScript ‘==` operation.
Constructor Details
#initialize(value = nil) ⇒ Literal
Creates a new literal.
22 23 24 |
# File 'lib/sass/script/literal.rb', line 22 def initialize(value = nil) @value = value end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the Ruby value of the literal. The type of this value varies based on the subclass.
17 18 19 |
# File 'lib/sass/script/literal.rb', line 17 def value @value end |
Instance Method Details
#==(other) ⇒ Boolean
Compares this object with another.
164 165 166 |
# File 'lib/sass/script/literal.rb', line 164 def ==(other) eq(other).to_bool end |
#and(other) ⇒ Literal
The SassScript ‘and` operation.
40 41 42 |
# File 'lib/sass/script/literal.rb', line 40 def and(other) to_bool ? other : self end |
#comma(other) ⇒ Script::String
The SassScript ‘,` operation (e.g. `!a, !b`, `“foo”, “bar”`).
101 102 103 |
# File 'lib/sass/script/literal.rb', line 101 def comma(other) Sass::Script::String.new("#{self.to_s}, #{other.to_s}") end |
#concat(other) ⇒ Script::String
The SassScript default operation (e.g. ‘!a !b`, `“foo” “bar”`).
92 93 94 |
# File 'lib/sass/script/literal.rb', line 92 def concat(other) Sass::Script::String.new("#{self.to_s} #{other.to_s}") end |
#div(other) ⇒ Script::String
The SassScript ‘/` operation.
128 129 130 |
# File 'lib/sass/script/literal.rb', line 128 def div(other) Sass::Script::String.new("#{self.to_s}/#{other.to_s}") end |
#eq(other) ⇒ Bool
The SassScript ‘==` operation. **Note that this returns a Bool object, not a Ruby boolean**.
61 62 63 |
# File 'lib/sass/script/literal.rb', line 61 def eq(other) Sass::Script::Bool.new(self.class == other.class && self.value == other.value) end |
#inspect ⇒ String
Returns A readable representation of the literal.
151 152 153 |
# File 'lib/sass/script/literal.rb', line 151 def inspect value.inspect end |
#minus(other) ⇒ Script::String
The SassScript ‘-` operation.
119 120 121 |
# File 'lib/sass/script/literal.rb', line 119 def minus(other) Sass::Script::String.new("#{self.to_s}-#{other.to_s}") end |
#neq(other) ⇒ Bool
The SassScript ‘!=` operation. **Note that this returns a Bool object, not a Ruby boolean**.
72 73 74 |
# File 'lib/sass/script/literal.rb', line 72 def neq(other) Sass::Script::Bool.new(!eq(other).to_bool) end |
#or(other) ⇒ Literal
The SassScript ‘or` operation.
50 51 52 |
# File 'lib/sass/script/literal.rb', line 50 def or(other) to_bool ? self : other end |
#perform(environment) ⇒ Literal
Evaluates the literal.
30 31 32 |
# File 'lib/sass/script/literal.rb', line 30 def perform(environment) self end |
#plus(other) ⇒ Script::String
The SassScript ‘+` operation.
110 111 112 |
# File 'lib/sass/script/literal.rb', line 110 def plus(other) Sass::Script::String.new(self.to_s + other.to_s) end |
#to_bool ⇒ Boolean
Returns ‘true` (the Ruby boolean value).
156 157 158 |
# File 'lib/sass/script/literal.rb', line 156 def to_bool true end |
#to_i ⇒ Fixnum
Returns The integer value of this literal.
170 171 172 |
# File 'lib/sass/script/literal.rb', line 170 def to_i raise Sass::SyntaxError.new("#{self.inspect} is not an integer.") end |
#unary_div ⇒ Script::String
The SassScript unary ‘/` operation (e.g. `/!a`).
146 147 148 |
# File 'lib/sass/script/literal.rb', line 146 def unary_div Sass::Script::String.new("/#{self.to_s}") end |
#unary_minus ⇒ Script::String
The SassScript unary ‘-` operation (e.g. `-!a`).
137 138 139 |
# File 'lib/sass/script/literal.rb', line 137 def unary_minus Sass::Script::String.new("-#{self.to_s}") end |