lib/wlang/scope.rb in wlang-2.0.0.beta vs lib/wlang/scope.rb in wlang-2.0.0

- old
+ new

@@ -10,22 +10,30 @@ def self.root @root ||= RootScope.new end - def self.coerce(arg, parent = root) + def self.coerce(arg, parent = nil) + return arg if Scope===arg && parent.nil? + parent ||= root clazz = case arg - when Binding - BindingScope - when Scope - ProxyScope - else - ObjectScope - end + when Binding + BindingScope + when Scope + ProxyScope + when Proc + ProcScope + else + ObjectScope + end clazz.new(arg, parent) end + def self.chain(scopes) + scopes.compact.inject(nil){|parent,child| Scope.coerce(child, parent)} || root + end + def push(x) Scope.coerce(x, self) end def pop @@ -53,5 +61,6 @@ end # module WLang require 'wlang/scope/root_scope' require 'wlang/scope/proxy_scope' require 'wlang/scope/object_scope' require 'wlang/scope/binding_scope' +require 'wlang/scope/proc_scope'