Class: Rusty::Scope

Inherits:
DX
  • Object
show all
Defined in:
lib/rusty/scope.rb

Overview

A Rusty output scope, is related to a input node, and might or might not have a parent.

Constant Summary

Constants inherited from DX

DX::EXCLUSIVE_DICT_METHODS, DX::EXCLUSIVE_LIST_METHODS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from DX

#dict?, #inspect, #list?, #method_missing, to_ruby, #to_ruby

Constructor Details

#initialize(node, parent = nil) ⇒ Scope

Returns a new instance of Scope.



13
14
15
# File 'lib/rusty/scope.rb', line 13

def initialize(node, parent=nil)
  @node, @parent = node, parent
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Rusty::DX

Instance Attribute Details

#nodeObject

Returns the value of attribute node.



10
11
12
# File 'lib/rusty/scope.rb', line 10

def node
  @node
end

Instance Method Details

#has_name?(name) ⇒ Boolean

Does this scope matches a given name?

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/rusty/scope.rb', line 18

def has_name?(name)
  return @parent.nil? if name == "document"

  node.name == name || node.has_class?(name)
end

#up! {|_self| ... } ⇒ Object

yields all nodes starting at self up to the top.

Yields:

  • (_self)

Yield Parameters:

  • _self (Rusty::Scope)

    the object that the method was called on



25
26
27
28
# File 'lib/rusty/scope.rb', line 25

def up!(&block)
  yield(self)
  @parent.up!(&block) if @parent
end