Class: Yadriggy::InstanceVariable
- Defined in:
- lib/yadriggy/ast.rb,
lib/yadriggy/ast_value.rb
Overview
Instance variable and class variable, such as @x
and @@x
.
The value returned by name
contains @
.
Instance Attribute Summary
Attributes inherited from Name
Attributes inherited from ASTnode
Class Method Summary collapse
Instance Method Summary collapse
-
#accept(evaluator) ⇒ void
A method for Visitor pattern.
- #const_value ⇒ Object
-
#initialize(sexp) ⇒ InstanceVariable
constructor
A new instance of InstanceVariable.
- #value ⇒ Object
- #value_in_class(clazz) ⇒ Object
Methods inherited from Name
Methods inherited from ASTnode
#add_child, #add_children, #const_value_in_class, #get_context_class, #get_receiver_object, #is_proc?, #pretty_print, #root, #source_location, #source_location_string
Constructor Details
#initialize(sexp) ⇒ InstanceVariable
Returns a new instance of InstanceVariable.
202 203 204 |
# File 'lib/yadriggy/ast.rb', line 202 def initialize(sexp) super(sexp) end |
Class Method Details
.tags ⇒ Object
200 |
# File 'lib/yadriggy/ast.rb', line 200 def self.() [:@ivar, :@cvar] end |
Instance Method Details
#accept(evaluator) ⇒ void
This method returns an undefined value.
A method for Visitor pattern.
209 210 211 |
# File 'lib/yadriggy/ast.rb', line 209 def accept(evaluator) evaluator.instance_variable(self) end |
#const_value ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/yadriggy/ast_value.rb', line 218 def const_value() if name.start_with?("@@") clazz = get_context_class if clazz.frozen? && clazz.class_variable_defined?(name) return clazz.class_variable_get(name) end elsif name.start_with?("@") obj = get_receiver_object if obj.frozen? && obj&.instance_variable_defined?(name) return obj.instance_variable_get(name) end end Undef end |
#value ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/yadriggy/ast_value.rb', line 190 def value() if name.start_with?("@@") clazz = get_context_class if clazz.class_variable_defined?(name) return clazz.class_variable_get(name) end elsif name.start_with?("@") obj = get_receiver_object if obj&.instance_variable_defined?(name) return obj.instance_variable_get(name) end end Undef end |
#value_in_class(clazz) ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/yadriggy/ast_value.rb', line 206 def value_in_class(clazz) if name.start_with?("@@") if clazz.class_variable_defined?(name) return clazz.class_variable_get(name) else Undef end else value end end |