Class: WLang::Scope::ObjectScope

Inherits:
WLang::Scope show all
Defined in:
lib/wlang/scope/object_scope.rb

Direct Known Subclasses

SinatraScope

Instance Attribute Summary

Attributes inherited from WLang::Scope

#parent, #subject

Instance Method Summary collapse

Methods inherited from WLang::Scope

chain, coerce, #evaluate, #initialize, null, #pop, #push, #root, #subjects, #with

Constructor Details

This class inherits a constructor from WLang::Scope

Instance Method Details

#fetch(key, dialect = nil, unfound = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/wlang/scope/object_scope.rb', line 5

def fetch(key, dialect = nil, unfound = nil)
  s = subject

  # self special case
  if key == :self
    return s
  end

  # hash indirect access
  if s.respond_to?(:has_key?)
    return s[key]      if s.has_key?(key)
    return s[key.to_s] if s.has_key?(key.to_s)
  end

  # getter
  if s.respond_to?(key)
    return s.send(key)
  end

  safe_parent.fetch(key, dialect, unfound)
rescue NameError
  safe_parent.fetch(key, dialect, unfound)
end

#inspectObject



34
35
36
# File 'lib/wlang/scope/object_scope.rb', line 34

def inspect
  "ObjectScope(#{subject.inspect})"
end

#to_sObject



29
30
31
32
# File 'lib/wlang/scope/object_scope.rb', line 29

def to_s
  subj = subject.is_a?(Scope) ? subject.to_s : subject.class
  "ObjectScope(#{subj})"
end