#-- # =========================================================================== # Copyright (c) 2005-2017 Christopher Kleckner # All rights reserved # # This file is part of the Rio library for ruby. # # Rio is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # Rio is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Rio; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # =========================================================================== #++ # module RIO module Cx autoload :Methods,'rio/context/methods' end end module RIO module Cx #:nodoc: all class Vars def initialize(h=Hash.new,exp=Hash.new) @values = h @explicit = exp end def initialize_copy(*args) super @values = @values.clone @explicit = @explicit.clone end BEQUEATH_KEYS = %w[chomp strip rename closeoneof closeoncopy] def bequeath(oldcx) keys = BEQUEATH_KEYS ncx = oldcx.clone #ncx = Vars.new keys.each { |key| ncx.set_(key,@values[key]) if @values.has_key?(key) } ncx end def delete(key) @values.delete(key) @explicit.delete(key) end def get_keystate(key) key_exists = @values.key?(key) key_val = @values[key] key_explicit = @explicit[key] [key,key_exists,key_val,key_explicit] end def set_keystate(key,key_exists,key_val,key_explicit) if(key_exists) then @values[key] = key_val @explicit[key] = key_explicit else @values.delete(key) @explicit.delete(key) end end def set_(key,val) @values[key] = val unless @explicit[key] end def []=(key,val) @values[key] = val @explicit[key] = true end def to_h vary = {} @values.each { |k,v| name = k name += '_' unless @explicit[k] vary[name] = v } vary end def inspect() str = sprintf('#