Class: Psych::Pure::Comments
- Inherits:
-
Object
- Object
- Psych::Pure::Comments
- Defined in:
- lib/psych/pure.rb
Overview
Represents the set of comments on a node.
Instance Attribute Summary collapse
-
#leading ⇒ Object
readonly
Returns the value of attribute leading.
-
#trailing ⇒ Object
readonly
Returns the value of attribute trailing.
Instance Method Summary collapse
-
#initialize ⇒ Comments
constructor
A new instance of Comments.
- #initialize_dup(other) ⇒ Object
- #leading_comment(comment) ⇒ Object
- #merge(other) ⇒ Object
- #trailing_comment(comment) ⇒ Object
-
#without_leading ⇒ Object
Execute the given block without the leading comments being visible.
Constructor Details
#initialize ⇒ Comments
Returns a new instance of Comments.
177 178 179 180 |
# File 'lib/psych/pure.rb', line 177 def initialize @leading = [] @trailing = [] end |
Instance Attribute Details
#leading ⇒ Object (readonly)
Returns the value of attribute leading.
175 176 177 |
# File 'lib/psych/pure.rb', line 175 def leading @leading end |
#trailing ⇒ Object (readonly)
Returns the value of attribute trailing.
175 176 177 |
# File 'lib/psych/pure.rb', line 175 def trailing @trailing end |
Instance Method Details
#initialize_dup(other) ⇒ Object
190 191 192 193 194 |
# File 'lib/psych/pure.rb', line 190 def initialize_dup(other) super @leading = other.leading.dup @trailing = other.trailing.dup end |
#leading_comment(comment) ⇒ Object
182 183 184 |
# File 'lib/psych/pure.rb', line 182 def leading_comment(comment) @leading << comment end |
#merge(other) ⇒ Object
196 197 198 199 |
# File 'lib/psych/pure.rb', line 196 def merge(other) @leading.concat(other.leading) @trailing.concat(other.trailing) end |
#trailing_comment(comment) ⇒ Object
186 187 188 |
# File 'lib/psych/pure.rb', line 186 def trailing_comment(comment) @trailing << comment end |
#without_leading ⇒ Object
Execute the given block without the leading comments being visible. This is used when a node has already handled its child nodes' leading comments, so they should not be processed again.
204 205 206 207 208 209 210 211 212 213 |
# File 'lib/psych/pure.rb', line 204 def without_leading leading = @leading begin @leading = [] yield ensure @leading = leading end end |