Class: Steep::AST::Types::Literal
- Inherits:
-
Object
- Object
- Steep::AST::Types::Literal
- Defined in:
- lib/steep/ast/types/literal.rb
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #back_type ⇒ Object
- #free_variables ⇒ Object
- #hash ⇒ Object
-
#initialize(value:, location: nil) ⇒ Literal
constructor
A new instance of Literal.
- #level ⇒ Object
- #subst(s) ⇒ Object
- #to_s ⇒ Object
- #with_location(new_location) ⇒ Object
Constructor Details
#initialize(value:, location: nil) ⇒ Literal
Returns a new instance of Literal.
8 9 10 11 |
# File 'lib/steep/ast/types/literal.rb', line 8 def initialize(value:, location: nil) @location = location @value = value end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
5 6 7 |
# File 'lib/steep/ast/types/literal.rb', line 5 def location @location end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
6 7 8 |
# File 'lib/steep/ast/types/literal.rb', line 6 def value @value end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
13 14 15 16 |
# File 'lib/steep/ast/types/literal.rb', line 13 def ==(other) other.is_a?(Literal) && other.value == value end |
#back_type ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/steep/ast/types/literal.rb', line 44 def back_type klass = case value when Integer Builtin::Integer when String Builtin::String when Symbol Builtin::Symbol else raise "Unexpected literal type: #{value.inspect}" end Name::Instance.new(name: klass.module_name, args: [], location: location) end |
#free_variables ⇒ Object
32 33 34 |
# File 'lib/steep/ast/types/literal.rb', line 32 def free_variables Set.new end |
#hash ⇒ Object
18 19 20 |
# File 'lib/steep/ast/types/literal.rb', line 18 def hash self.class.hash end |
#level ⇒ Object
36 37 38 |
# File 'lib/steep/ast/types/literal.rb', line 36 def level [0] end |
#subst(s) ⇒ Object
24 25 26 |
# File 'lib/steep/ast/types/literal.rb', line 24 def subst(s) self end |
#to_s ⇒ Object
28 29 30 |
# File 'lib/steep/ast/types/literal.rb', line 28 def to_s value.inspect end |
#with_location(new_location) ⇒ Object
40 41 42 |
# File 'lib/steep/ast/types/literal.rb', line 40 def with_location(new_location) self.class.new(location: new_location) end |