Class: Steep::AST::Types::Literal
- Includes:
- Helper::NoChild, Helper::NoFreeVariables
- Defined in:
- lib/steep/ast/types/literal.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #back_type ⇒ Object
- #hash ⇒ Object
-
#initialize(value:) ⇒ Literal
constructor
A new instance of Literal.
- #level ⇒ Object
- #subst(s) ⇒ Object
- #to_s ⇒ Object
Methods included from Helper::NoChild
Methods included from Helper::NoFreeVariables
Constructor Details
#initialize(value:) ⇒ Literal
Returns a new instance of Literal.
7 8 9 |
# File 'lib/steep/ast/types/literal.rb', line 7 def initialize(value:) @value = value end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'lib/steep/ast/types/literal.rb', line 5 def value @value end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
11 12 13 14 |
# File 'lib/steep/ast/types/literal.rb', line 11 def ==(other) other.is_a?(Literal) && other.value == value end |
#back_type ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/steep/ast/types/literal.rb', line 38 def back_type klass = case value when Integer Builtin::Integer when String Builtin::String when Symbol Builtin::Symbol when true Builtin::TrueClass when false Builtin::FalseClass else raise "Unexpected literal type: #{(_ = value).inspect}" end Name::Instance.new(name: klass.module_name, args: []) end |
#hash ⇒ Object
16 17 18 |
# File 'lib/steep/ast/types/literal.rb', line 16 def hash self.class.hash end |
#level ⇒ Object
34 35 36 |
# File 'lib/steep/ast/types/literal.rb', line 34 def level [0] end |
#subst(s) ⇒ Object
22 23 24 |
# File 'lib/steep/ast/types/literal.rb', line 22 def subst(s) self end |
#to_s ⇒ Object
26 27 28 |
# File 'lib/steep/ast/types/literal.rb', line 26 def to_s value.inspect end |