Class: YARP::CaseNode
- Inherits:
-
YARPNode
- Object
- YARPNode
- YARP::CaseNode
- Defined in:
- lib/yarp/node.rb,
ext/yarp/api_node.c
Overview
Represents the use of a case statement.
case true ^^^^^^^^^ when false end
Instance Attribute Summary collapse
-
#case_keyword_loc ⇒ Object
readonly
attr_reader case_keyword_loc: Location.
-
#conditions ⇒ Object
readonly
attr_reader conditions: Array.
-
#consequent ⇒ Object
readonly
attr_reader consequent: ElseNode?.
-
#end_keyword_loc ⇒ Object
readonly
attr_reader end_keyword_loc: Location.
-
#predicate ⇒ Object
readonly
attr_reader predicate: Node?.
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void.
-
#case_keyword ⇒ Object
def case_keyword: () -> String.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#copy(**params) ⇒ Object
def copy: (**params) -> CaseNode.
- #deconstruct_keys(keys) ⇒ Object
-
#end_keyword ⇒ Object
def end_keyword: () -> String.
-
#initialize(predicate, conditions, consequent, case_keyword_loc, end_keyword_loc, location) ⇒ CaseNode
constructor
def initialize: (predicate: Node?, conditions: Array, consequent: ElseNode?, case_keyword_loc: Location, end_keyword_loc: Location, location: Location) -> void.
- #inspect(inspector = NodeInspector.new) ⇒ Object
Constructor Details
#initialize(predicate, conditions, consequent, case_keyword_loc, end_keyword_loc, location) ⇒ CaseNode
def initialize: (predicate: Node?, conditions: Array, consequent: ElseNode?, case_keyword_loc: Location, end_keyword_loc: Location, location: Location) -> void
1942 1943 1944 1945 1946 1947 1948 1949 |
# File 'lib/yarp/node.rb', line 1942 def initialize(predicate, conditions, consequent, case_keyword_loc, end_keyword_loc, location) @predicate = predicate @conditions = conditions @consequent = consequent @case_keyword_loc = case_keyword_loc @end_keyword_loc = end_keyword_loc @location = location end |
Instance Attribute Details
#case_keyword_loc ⇒ Object (readonly)
attr_reader case_keyword_loc: Location
1936 1937 1938 |
# File 'lib/yarp/node.rb', line 1936 def case_keyword_loc @case_keyword_loc end |
#conditions ⇒ Object (readonly)
attr_reader conditions: Array
1930 1931 1932 |
# File 'lib/yarp/node.rb', line 1930 def conditions @conditions end |
#consequent ⇒ Object (readonly)
attr_reader consequent: ElseNode?
1933 1934 1935 |
# File 'lib/yarp/node.rb', line 1933 def consequent @consequent end |
#end_keyword_loc ⇒ Object (readonly)
attr_reader end_keyword_loc: Location
1939 1940 1941 |
# File 'lib/yarp/node.rb', line 1939 def end_keyword_loc @end_keyword_loc end |
#predicate ⇒ Object (readonly)
attr_reader predicate: Node?
1927 1928 1929 |
# File 'lib/yarp/node.rb', line 1927 def predicate @predicate end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
1952 1953 1954 |
# File 'lib/yarp/node.rb', line 1952 def accept(visitor) visitor.visit_case_node(self) end |
#case_keyword ⇒ Object
def case_keyword: () -> String
1987 1988 1989 |
# File 'lib/yarp/node.rb', line 1987 def case_keyword case_keyword_loc.slice end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
1957 1958 1959 |
# File 'lib/yarp/node.rb', line 1957 def child_nodes [predicate, *conditions, consequent] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
1962 1963 1964 |
# File 'lib/yarp/node.rb', line 1962 def comment_targets [*predicate, *conditions, *consequent, case_keyword_loc, end_keyword_loc] end |
#copy(**params) ⇒ Object
def copy: (**params) -> CaseNode
1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 |
# File 'lib/yarp/node.rb', line 1967 def copy(**params) CaseNode.new( params.fetch(:predicate) { predicate }, params.fetch(:conditions) { conditions }, params.fetch(:consequent) { consequent }, params.fetch(:case_keyword_loc) { case_keyword_loc }, params.fetch(:end_keyword_loc) { end_keyword_loc }, params.fetch(:location) { location }, ) end |
#deconstruct_keys(keys) ⇒ Object
1982 1983 1984 |
# File 'lib/yarp/node.rb', line 1982 def deconstruct_keys(keys) { predicate: predicate, conditions: conditions, consequent: consequent, case_keyword_loc: case_keyword_loc, end_keyword_loc: end_keyword_loc, location: location } end |
#end_keyword ⇒ Object
def end_keyword: () -> String
1992 1993 1994 |
# File 'lib/yarp/node.rb', line 1992 def end_keyword end_keyword_loc.slice end |
#inspect(inspector = NodeInspector.new) ⇒ Object
1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 |
# File 'lib/yarp/node.rb', line 1996 def inspect(inspector = NodeInspector.new) inspector << inspector.header(self) if (predicate = self.predicate).nil? inspector << "├── predicate: ∅\n" else inspector << "├── predicate:\n" inspector << predicate.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) end inspector << "├── conditions: #{inspector.list("#{inspector.prefix}│ ", conditions)}" if (consequent = self.consequent).nil? inspector << "├── consequent: ∅\n" else inspector << "├── consequent:\n" inspector << consequent.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) end inspector << "├── case_keyword_loc: #{inspector.location(case_keyword_loc)}\n" inspector << "└── end_keyword_loc: #{inspector.location(end_keyword_loc)}\n" inspector.to_str end |