[ruby-gnome2-doc-cvs] [Ruby-GNOME2 Project Website] create - tut-gtk2-glib-env

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2009年 2月 1日 (日) 10:23:10 JST


-------------------------
REMOTE_ADDR = 74.15.84.244
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-glib-env
-------------------------
TITLE       = tut-gtk2-glib-env
KEYWORD     = 
= GLib Short Tutorial
{{link "tut-gtk2-glib", "tut-gtk2-glib", "tut-gtk", tut-gtk2-glib-util}}

= Environment Variables

If you are creating an application that is going to be run on different platforms, it can be rather difficult to deal with incompatible environment organizations and setups. GLib provides a set of methods that return values of different environment variables. Perhaps the the list interesting and the most relevant to this paragraph is the following method:

--- GLib.listenv

     * Returns an aray containing all the available environment variables. It does not list any values associated with these variables. That you need to extract yourself:
      GLib.listenv.each {|e| puts GLib.getenv(e) }


Following are a number of methods you can use to obtain and even manipulate the values of the available environment variables.



--- GLib.check_version?(major, minor, micro)
     Check out a hypothetical version of library calls you would like to run against the GLib installed with your Ruby. For instance you would need to run GLib 2.12.3. To see if your installed GLib is younger or of the same age as what your requirements are run GLib.check_version?(2, 12, 3); - ((*FIXME ???*)) 
     * major 
     * minor 
     * micro
     * Returns: true if major, minor, micro are less or equal to the GLib installed version


--- GLib.getenv(env_var_name)

     Obtain the value of system environment variable. For example:
      home = GLib.getenv("HOME")  # -> "/users/bob"
     * env_var_name: name of the environment variable
     * Returns: the value of the environment variable, or nil


--- GLib.homedir

     This "GLib" class method provides a compatible way to obtain current user's home directory regardless of the operating system you are on. (The original GLib's C function name is "g_get_home_dir()")

     * Returns: a string representing current user's home directory name.

--- GLib.host_name

     * Returns: a string representing hostname.

--- GLib.path_get_basename(path)
     Obtain base name from a path i.e.: ("/aaa/bbb/ccc" -> "ccc"). NOTE: this function is cross platform compatible it does not care what the File::SEPARATOR is.
     * path: a string representing either an absolute or a relative the directory path.
     * Returns: base name (last item from the path).

--- GLib.path_get_dirname(path)
     Obtain the folder in which the base name from a path sits i.e.: ("/aaa/bbb/ccc" -> "/aaa/bbb")
     * path: a string representing either an absolute or a relative the directory path.
     * Returns: folder in which the last item from the path resides. NOTE: this function is cross platform compatible it does not care what the File::SEPARATOR is.

--- GLib.path_is_absolute?(path)

     * path: a string representing either an absolute or a relative the directory path.
     * Returns: true the string in <path> represents an absolute path. NOTE: this function is cross platform compatible it does not care what the File::SEPARATOR is.

--- GLib.path_skip_root(path)

     * path: a string representing either an absolute or a relative the directory path.
     Removes the root directory from the path - (i.e.: "/aaa/bbb/ccc" -> "aaa/bbb/ccc")
     * Returns: the relative path without root (/).

--- GLib.setenv(env_var_name, new_value)

     Sets the  environment variable <env_var_nameto> a new value <new_value>. The environment variable is set only for the current Ruby session. No system settings are effected. For example:
      home = GLib.getenv("HOME")                      -> "/users/bob
      ok = GLib.setenv("HOME", "whatever/whereever")  -> true
      home = GLib.getenv("HOME")                      -> "whatever/whereever"
     * env_var_name: name of the environment variable
     * new_value: new value the environment variable <env_var_nameto> is to be set to.
     * Returns: the value of the environment variable, or nil


--- GLib.prgname

     Retrieves program name
     * Returns: program name - (on unix-like platforms the same as 'basename($0)')

--- GLib.prgname=(prog_name)

     Sets program name to the value in <prog_name>
     * Returns: Returns: program name - (on unix-like platforms the same as  'basename($0)')

--- GLib.real_name

     * Returns: real name of the user as opposed to "log-in name"

--- GLib.application_name
     Retrieves the application name.
     * Returns: application name

--- GLib.application_name=(new_name) 
     Sets the application name and GLib.prgname name to <new_name>.
     * Returns: application name


--- GLib.set_application_name
     Sets the application name and GLib::program name to <new_name>.  - same as GLib.application_name = (new_name)
     * Returns: application name

--- GLib.set_prgname

     Sets program name - same as GLib.prgname=(prog_name)
     * Returns: Returns: program name - (on unix-like platforms the same as  'basename($0)')

--- GLib.tmp_dir

     * Returns: temporary directory name

--- GLib.user_name

     * Returns: user's log-in name.

--- GLib.os_beos?

     * Returns: true if run on BeOS, otherwise false

--- GLib.os_unix?

     * Returns: true if run on Unix-like OS, otherwise false

--- GLib.os_win32?

     * Returns: true if run on Unix-like OS, otherwise false




ruby-gnome2-cvs メーリングリストの案内
Back to archive index