Top Level Namespace
Defined Under Namespace
Modules: Comparable, Enumerable, Errno, FileTest, GC, Kernel, Marshal, Math, ObjectSpace, Process, Signal, UnicodeNormalize, Warning Classes: ArgumentError, Array, BasicObject, Binding, Class, ClosedQueueError, Complex, Continuation, Data, Dir, ENV, EOFError, Encoding, EncodingError, Enumerator, Exception, FalseClass, Fiber, FiberError, File, Float, FloatDomainError, FrozenError, Hash, IO, IOError, IndexError, Integer, Interrupt, KeyError, LoadError, LocalJumpError, MatchData, Method, Module, NameError, NilClass, NoMatchingPatternError, NoMatchingPatternKeyError, NoMemoryError, NoMethodError, NotImplementedError, Numeric, Object, Proc, Ractor, Random, Range, RangeError, Rational, Refinement, Regexp, RegexpError, RubyVM, RuntimeError, ScriptError, SecurityError, SignalException, StandardError, StopIteration, String, Struct, Symbol, SyntaxError, SystemCallError, SystemExit, SystemStackError, Thread, ThreadError, ThreadGroup, Time, TracePoint, TrueClass, TypeError, UnboundMethod, UncaughtThrowError, ZeroDivisionError, fatal
Constant Summary collapse
- STDIN =
Holds the original stdin
rb_stdin
- STDOUT =
Holds the original stdout
rb_stdout
- STDERR =
Holds the original stderr
rb_stderr
- ARGF =
$ ruby argf.rb –verbose file1 file2
ARGV #=> ["--verbose", "file1", "file2"] option = ARGV.shift #=> "--verbose" ARGV #=> ["file1", "file2"]
You can now use ARGF to work with a concatenation of each of these named files. For instance, ARGF.read will return the contents of file1 followed by the contents of file2.
After a file in
ARGV
has been read ARGF removes it from the Array. Thus, after all files have been readARGV
will be empty.You can manipulate
ARGV
yourself to control what ARGF operates on. If you remove a file fromARGV
, it is ignored by ARGF; if you add files toARGV
, they are treated as if they were named on the command line. For example:ARGV.replace ["file1"] ARGF.readlines # Returns the contents of file1 as an Array ARGV #=> [] ARGV.replace ["file2", "file3"] ARGF.read # Returns the contents of file2 and file3
If
ARGV
is empty, ARGF acts as if it contained"-"
that makes ARGF read from STDIN, i.e. the data piped or typed to your script. For example:$ echo "glark" | ruby -e 'p ARGF.read' "glark\n" $ echo Glark > file1 $ echo "glark" | ruby -e 'p ARGF.read' -- - file1 "glark\nGlark\n"
ARGF is a stream designed for use in scripts that process files given as command-line arguments or passed in via STDIN. The arguments passed to your script are stored in the +ARGV+ Array, one argument per element. ARGF assumes that any arguments that aren't filenames have been removed from +ARGV+. For example
- TOPLEVEL_BINDING =
The Binding of the top level scope
rb_binding_new()
- ARGV =
ARGV contains the command line arguments used to run ruby.
A library like OptionParser can be used to process command-line arguments.
rb_argv
- RUBY_VERSION =
MKSTR(version)
/* MKSTR(version) */ version
- RUBY_RELEASE_DATE =
The date this ruby was released
MKSTR(release_date)
- RUBY_PLATFORM =
The platform for this ruby
MKSTR(platform)
- RUBY_PATCHLEVEL =
The patchlevel for this ruby. If this is a development build of ruby the patchlevel will be -1
MKINT(patchlevel)
- RUBY_REVISION =
The GIT commit hash for this ruby.
MKSTR(revision)
- RUBY_COPYRIGHT =
The copyright string for ruby
MKSTR(copyright)
- RUBY_ENGINE =
MKSTR(engine)
/* MKSTR(engine) */ ruby_engine_name
- RUBY_ENGINE_VERSION =
MKSTR(version)
/* MKSTR(version) */ version
- RUBY_DESCRIPTION =
MKSTR(description)
/* MKSTR(description) */ description