public static MutableString SetVariable(RubyContext /*!*/ context, object /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ name, [DefaultProtocol] MutableString value)
        {
            PlatformAdaptationLayer pal = context.DomainManager.Platform;

            pal.SetEnvironmentVariable(name.ConvertToString(), (value != null) ? value.ConvertToString() : null);
            return(value);
        }
        private static void Update(RubyContext /*!*/ context, List <KeyValuePair <string, string> > /*!*/ values)
        {
            PlatformAdaptationLayer pal = context.DomainManager.Platform;

            foreach (var pair in values)
            {
                pal.SetEnvironmentVariable(pair.Key, pair.Value);
            }
        }
        public static object Clear(RubyContext /*!*/ context, object /*!*/ self)
        {
            PlatformAdaptationLayer pal = context.DomainManager.Platform;

            foreach (DictionaryEntry entry in pal.GetEnvironmentVariables())
            {
                pal.SetEnvironmentVariable(entry.Key.ToString(), null);
            }
            return(self);
        }
Exemplo n.º 4
0
 private static void SetHome()
 {
     try {
         PlatformAdaptationLayer platform = PlatformAdaptationLayer.Default;
         string homeDir = RubyUtils.GetHomeDirectory(platform);
         platform.SetEnvironmentVariable("HOME", homeDir);
     } catch (System.Security.SecurityException e) {
         // Ignore EnvironmentPermission exception
         if (e.PermissionType != typeof(System.Security.Permissions.EnvironmentPermission))
         {
             throw;
         }
     }
 }
        public static object Shift(RubyContext /*!*/ context, object /*!*/ self)
        {
            PlatformAdaptationLayer pal       = context.DomainManager.Platform;
            IDictionary             variables = pal.GetEnvironmentVariables();

            if (variables.Count == 0)
            {
                return(null);
            }
            RubyArray result = new RubyArray(2);

            foreach (DictionaryEntry entry in pal.GetEnvironmentVariables())
            {
                string key = entry.Key.ToString();
                result.Add(MutableString.Create(key).Freeze());
                result.Add(MutableString.Create(entry.Value.ToString()).Freeze());
                pal.SetEnvironmentVariable(key, null);
                break;
            }
            return(result);
        }