Class: TEALrb::Rewriters::WhileRewriter
- Defined in:
- lib/tealrb/rewriters.rb
Class Attribute Summary collapse
-
.while_count ⇒ Object
Returns the value of attribute while_count.
Attributes inherited from Rewriter
Instance Method Summary collapse
-
#initialize(*args) ⇒ WhileRewriter
constructor
A new instance of WhileRewriter.
- #on_while(node) ⇒ Object
- #while_count ⇒ Object
Methods inherited from Rewriter
Constructor Details
#initialize(*args) ⇒ WhileRewriter
Returns a new instance of WhileRewriter.
258 259 260 261 262 |
# File 'lib/tealrb/rewriters.rb', line 258 def initialize(*args) self.class.while_count = {} self.class.while_count[Thread.current] ||= 0 super end |
Class Attribute Details
.while_count ⇒ Object
Returns the value of attribute while_count.
255 256 257 |
# File 'lib/tealrb/rewriters.rb', line 255 def while_count @while_count end |
Instance Method Details
#on_while(node) ⇒ Object
268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/tealrb/rewriters.rb', line 268 def on_while(node) cond_node = node.children.first replace( node.loc.keyword, ":while#{while_count}_condition;#{cond_node.source};bz :while#{while_count}_end; :while#{while_count}_logic;" ) replace(node.loc.begin, '') if node.loc.begin replace(node.loc.end, "b :while#{while_count}_condition;:while#{while_count}_end") replace(cond_node.loc.expression, '') super end |
#while_count ⇒ Object
264 265 266 |
# File 'lib/tealrb/rewriters.rb', line 264 def while_count self.class.while_count[Thread.current] end |