Class: Teepee::Scope

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(father = nil) ⇒ Scope

Returns a new instance of Scope.



42
43
44
45
# File 'lib/teepee/scope.rb', line 42

def initialize father = nil
  @father = father
  @variables = Hash.new
end

Instance Attribute Details

#fatherObject

Returns the value of attribute father.



40
41
42
# File 'lib/teepee/scope.rb', line 40

def father
  @father
end

#variablesObject

Returns the value of attribute variables.



40
41
42
# File 'lib/teepee/scope.rb', line 40

def variables
  @variables
end

Instance Method Details

#[](key) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/teepee/scope.rb', line 60

def [](key)
  if variables.has_key? key
    variables[key]
  elsif father
    father[key]
  end
end

#[]=(key, value) ⇒ Object



68
69
70
# File 'lib/teepee/scope.rb', line 68

def []=(key, value)
  variables[key] = value
end

#deriveObject



84
85
86
# File 'lib/teepee/scope.rb', line 84

def derive
  self.class.new self
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
58
# File 'lib/teepee/scope.rb', line 55

def has_key? key
  variables.has_key?(key) or
    (not orphan? and father.has_key?(key))
end

#keysObject



51
52
53
# File 'lib/teepee/scope.rb', line 51

def keys
  variables.keys
end

#orphan?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/teepee/scope.rb', line 47

def orphan?
  not father or father.nil?
end

#scope_for(key) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/teepee/scope.rb', line 72

def scope_for key
  if variables.has_key? key
    self
  else
    father.scope_for key
  end
end

#shadow?(key) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/teepee/scope.rb', line 80

def shadow? key
  has_key?(key) and not orphan? and father.has_key?(key)
end