Objectis the parent class of all classes in Ruby. Its methods are therefore available to all objects unless explicitly overridden.

Objectmixes in the Kernelmodule, making the built-in kernel functions globally accessible. Although the instance methods of Objectare defined by the Kernel module, we have chosen to document them here for clarity.

In the descriptions of Object's methods, the parameter symbol refers to a symbol, which is either a quoted string or a Symbol(such as :name).

Namespace
Methods
#
C
D
R
#
C
D
E
F
G
H
I
K
L
M
N
O
P
R
S
T
U
W
X
Included Modules
Constants
TOPLEVEL_BINDING = rb_f_binding(ruby_top_self)
 
ENV = envtbl
 
STDIN = rb_stdin
 

constants to hold original stdin/stdout/stderr

STDOUT = rb_stdout
 
STDERR = rb_stderr
 
ARGF = argf
 
NIL = Qnil
 
TRUE = Qtrue
 
FALSE = Qfalse
 
MatchingData = rb_cMatch
 
DATA = f
 
ARGV = rb_argv
 
RUBY_VERSION = v
 
RUBY_RELEASE_DATE = d
 
RUBY_PLATFORM = p
 
RUBY_PATCHLEVEL = INT2FIX(RUBY_PATCHLEVEL)
 
RUBY_DESCRIPTION = tmp
 
RUBY_COPYRIGHT = tmp
 
VERSION = v
 

obsolete constants

RELEASE_DATE = d
 
PLATFORM = p
 
SCRIPT_LINES__ = {} unless defined? SCRIPT_LINES__
 
DRbObject = DRb::DRbObject
 
DRbUndumped = DRb::DRbUndumped
 
DRbIdConv = DRb::DRbIdConv
 
SLex = IRB::SLex
 
CONFIG = Config::MAKEFILE_CONFIG
 
ORIG_LIBPATH = ENV['LIB']
 
CXX_EXT = %w[cc cxx cpp]
 
SRC_EXT = %w[c m].concat(CXX_EXT)
 
EXPORT_PREFIX = config_string('EXPORT_PREFIX') {|s| s.strip}
 
COMMON_HEADERS = hdr.join("\n")
 
COMMON_LIBS = config_string('COMMON_LIBS', &split) || []
 
COMPILE_RULES = config_string('COMPILE_RULES', &split) || %w[.%s.%s:]
 
RULE_SUBST = config_string('RULE_SUBST')
 
COMPILE_C = config_string('COMPILE_C') || '$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<'
 
COMPILE_CXX = config_string('COMPILE_CXX') || '$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<'
 
TRY_LINK = config_string('TRY_LINK') || "$(CC) #{OUTFLAG}conftest $(INCFLAGS) $(CPPFLAGS) " \ "$(CFLAGS) $(src) $(LIBPATH) $(LDFLAGS) $(ARCH_FLAG) $(LOCAL_LIBS) $(LIBS)"
 
LINK_SO = config_string('LINK_SO') || if CONFIG["DLEXT"] == $OBJEXT "ld $(DLDFLAGS) -r -o $@ $(OBJS)\n" else "$(LDSHARED) #{OUTFLAG}$@ $(OBJS) " \ "$(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)" end
 
LIBPATHFLAG = config_string('LIBPATHFLAG') || ' -L"%s"'
 
RPATHFLAG = config_string('RPATHFLAG') || ''
 
LIBARG = config_string('LIBARG') || '-l%s'
 
CLEANINGS = " clean: @-$(RM) $(CLEANLIBS#{sep}) $(CLEANOBJS#{sep}) $(CLEANFILES#{sep}) distclean: clean @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES#{sep}) realclean: distclean "
 
Version = OptionParser::Version
 
NotImplementedError = NotImplementError
 
ParseError = Racc::ParseError
 
VERSION_STRING = %{RDoc V1.0.1 - 20041108}
 

See README.

SOAPMarshal = SOAP::Marshal
 
Synchronizer_m = Sync_m
 
Synchronizer = Sync
 
ThWait = ThreadsWait
 
TimeoutError = Timeout::Error # :nodoc:
 

Another name for Timeout::Error, defined for backwards compatibility with earlier versions of timeout.rb.

IPsocket = rb_cIPSocket
 
TCPsocket = rb_cTCPSocket
 
SOCKSsocket = rb_cSOCKSSocket
 
TCPserver = rb_cTCPServer
 
UDPsocket = rb_cUDPSocket
 
UNIXsocket = rb_cUNIXSocket
 
UNIXserver = rb_cUNIXServer
 
SRCFILES = <<SRC win32ole.c SRC
 
ChartTypeVal = -4100;
 

-4100 is the value for the Excel constant xl3DColumn.

Class Protected methods
new()

Not documented

static VALUE
rb_obj_dummy()
{
    return Qnil;
}
Instance Public methods
obj == other => true or false obj.equal?(other) => true or false obj.eql?(other) => true or false

Equality—At the Objectlevel, ==returns trueonly if objand otherare the same object. Typically, this method is overridden in descendent classes to provide class-specific meaning.

Unlike ==, the equal?method should never be overridden by subclasses: it is used to determine object identity (that is, a.equal?(b)iff ais the same object as b).

The eql?method returns trueif objand anObject have the same value. Used by Hashto test members for equality. For objects of class Object, eql?is synonymous with ==. Subclasses normally continue this tradition, but there are exceptions. Numerictypes, for example, perform type conversion across ==, but not across eql?, so:

1 == 1.0     #=> true
1.eql? 1.0   #=> false
static VALUE
rb_obj_equal(obj1, obj2)
    VALUE obj1, obj2;
{
    if (obj1 == obj2) return Qtrue;
    return Qfalse;
}
obj === other => true or false

Case Equality—For class Object, effectively the same as calling #==, but typically overridden by descendents to provide meaningful semantics in casestatements.

VALUE
rb_equal(obj1, obj2)
    VALUE obj1, obj2;
{
    VALUE result;
    if (obj1 == obj2) return Qtrue;
    result = rb_funcall(obj1, id_eq, 1, obj2);
    if (RTEST(result)) return Qtrue;
    return Qfalse;
}
obj =~ other => false

Pattern Match—Overridden by descendents (notably Regexpand String) to provide meaningful pattern-match semantics.

static VALUE
rb_obj_pattern_match(obj1, obj2)
    VALUE obj1, obj2;
{
    return Qfalse;
}
Complex(a, b = 0)

Creates a Complex number. aand bshould be Numeric. The result will be a+bi.

# File lib/complex.rb, line 86
def Complex(a, b = 0)
  if b == 0 and (a.kind_of?(Complex) or defined? Complex::Unify)
    a
  else
    Complex.new( a.real-b.imag, a.imag+b.real )
  end
end
DelegateClass(superclass)

The primary interface to this library. Use to setup delegation when defining your class.

class MyClass < DelegateClass( ClassToDelegateTo )    # Step 1
  def initialize
    super(obj_of_ClassToDelegateTo)                   # Step 2
  end
end
# File lib/delegate.rb, line 258
def DelegateClass(superclass)
  klass = Class.new
  methods = superclass.public_instance_methods(true)
  methods -= ::Kernel.public_instance_methods(false)
  methods |= ["to_s","to_a","inspect","==","=~","==="]
  klass.module_eval {
    def initialize(obj)  # :nodoc:
      @_dc_obj = obj
    end
    def method_missing(m, *args, &block)  # :nodoc:
      unless @_dc_obj.respond_to?(m)
        super(m, *args, &block)
      end
      @_dc_obj.__send__(m, *args, &block)
    end
    def respond_to?(m, include_private = false)  # :nodoc:
      return true if super
      return @_dc_obj.respond_to?(m, include_private)
    end
    def __getobj__  # :nodoc:
      @_dc_obj
    end
    def __setobj__(obj)  # :nodoc:
      raise ArgumentError, "cannot delegate to self" if self.equal?(obj)
      @_dc_obj = obj
    end
    def clone  # :nodoc:
      new = super
      new.__setobj__(__getobj__.clone)
      new
    end
    def dup  # :nodoc:
      new = super
      new.__setobj__(__getobj__.clone)
      new
    end
  }
  for method in methods
    begin
      klass.module_eval "        def #{method}(*args, &block)
          begin
            @_dc_obj.__send__(:#{method}, *args, &block)
          ensure
            $@.delete_if{|s| ::Delegator::IgnoreBacktracePat =~ s} if $@
          end
        end
", __FILE__, __LINE__+1
    rescue SyntaxError
      raise NameError, "invalid identifier %s" % method, caller(3)
    end
  end
  return klass
end
Rational(a, b = 1)

Creates a Rational number (i.e. a fraction). aand bshould be Integers:

Rational(1,3)           # -> 1/3

Note: trying to construct a Rational with floating point or real values produces errors:

Rational(1.1, 2.3)      # -> NoMethodError
# File lib/rational.rb, line 31
def Rational(a, b = 1)
  if a.kind_of?(Rational) && b == 1
    a
  else
    Rational.reduce(a, b)
  end
end
obj.__id__ => fixnum obj.object_id => fixnum

Returns an integer identifier for obj. The same number will be returned on all calls to idfor a given object, and no two active objects will share an id. Object#object_idis a different concept from the :namenotation, which returns the symbol id of name. Replaces the deprecated Object#id.

VALUE
rb_obj_id(VALUE obj)
{
    /*
     *                32-bit VALUE space
     *          MSB ------------------------ LSB
     *  false   00000000000000000000000000000000
     *  true    00000000000000000000000000000010
     *  nil     00000000000000000000000000000100
     *  undef   00000000000000000000000000000110
     *  symbol  ssssssssssssssssssssssss00001110
     *  object  oooooooooooooooooooooooooooooo00        = 0 (mod sizeof(RVALUE))
     *  fixnum  fffffffffffffffffffffffffffffff1
     *
     *                    object_id space
     *                                       LSB
     *  false   00000000000000000000000000000000
     *  true    00000000000000000000000000000010
     *  nil     00000000000000000000000000000100
     *  undef   00000000000000000000000000000110
     *  symbol   000SSSSSSSSSSSSSSSSSSSSSSSSSSS0        S...S % A = 4 (S...S = s...s * A + 4)
     *  object   oooooooooooooooooooooooooooooo0        o...o % A = 0
     *  fixnum  fffffffffffffffffffffffffffffff1        bignum if required
     *
     *  where A = sizeof(RVALUE)/4
     *
     *  sizeof(RVALUE) is
     *  20 if 32-bit, double is 4-byte aligned
     *  24 if 32-bit, double is 8-byte aligned
     *  40 if 64-bit
     */
    if (TYPE(obj) == T_SYMBOL) {
        return (SYM2ID(obj) * sizeof(RVALUE) + (4 << 2)) | FIXNUM_FLAG;
    }
    if (SPECIAL_CONST_P(obj)) {
        return LONG2NUM((long)obj);
    }
    return (VALUE)((long)obj|FIXNUM_FLAG);
}
obj.send(symbol [, args...]) => obj obj.__send__(symbol [, args...]) => obj

Invokes the method identified by symbol, passing it any arguments specified. You can use __send__if the name send clashes with an existing method in obj.

class Klass
  def hello(*args)
    "Hello " + args.join(' ')
  end
end
k = Klass.new
k.send :hello, "gentle", "readers"   #=> "Hello gentle readers"
static VALUE
rb_f_send(argc, argv, recv)
    int argc;
    VALUE *argv;
    VALUE recv;
{
    VALUE vid;
    if (argc == 0) rb_raise(rb_eArgError, "no method name given");
    vid = *argv++; argc--;
    PUSH_ITER(rb_block_given_p()?ITER_PRE:ITER_NOT);
    vid = rb_call(CLASS_OF(recv), recv, rb_to_id(vid), argc, argv, 1, Qundef);
    POP_ITER();
    return vid;
}
check_sizeof(type, headers = nil, &b)

Returns the size of the given type. You may optionally specify additional headersto search in for the type.

If found, a macro is passed as a preprocessor constant to the compiler using the type name, in uppercase, prepended with 'SIZEOF_', followed by the type name, followed by '=X' where 'X' is the actual size.

For example, if #check_sizeof('mystruct') returned 12, then the SIZEOF_MYSTRUCT=12 preprocessor macro would be passed to the compiler.

# File lib/mkmf.rb, line 912
def check_sizeof(type, headers = nil, &b)
  expr = "sizeof(#{type})"
  fmt = "%d"
  def fmt.%(x)
    x ? super : "failed"
  end
  checking_for checking_message("size of #{type}", headers), fmt do
    if size = try_constant(expr, headers, &b)
      $defs.push(format("-DSIZEOF_%s=%d", type.tr_cpp, size))
      size
    end
  end
end
chmod()

Change the mode of each FILE to OCTAL-MODE.

ruby -run -e chmod -- [OPTION] OCTAL-MODE FILE
-v          verbose
# File lib/un.rb, line 195
def chmod
  setup do |argv, options|
    mode = argv.shift.oct
    FileUtils.chmod mode, argv, options
  end
end
obj.class => class

Returns the class of obj, now preferred over Object#type, as an object's type in Ruby is only loosely tied to that object's class. This method must always be called with an explicit receiver, as classis also a reserved word in Ruby.

1.class      #=> Fixnum
self.class   #=> Object
VALUE
rb_obj_class(obj)
    VALUE obj;
{
    return rb_class_real(CLASS_OF(obj));
}
obj.clone → an_object

Produces a shallow copy of obj—the instance variables of objare copied, but not the objects they reference. Copies the frozen and tainted state of obj. See also the discussion under Object#dup.

class Klass
   attr_accessor :str
end
s1 = Klass.new      #=> #<Klass:0x401b3a38>
s1.str = "Hello"    #=> "Hello"
s2 = s1.clone       #=> #<Klass:0x401b3998 @str="Hello">
s2.str[1,4] = "i"   #=> "i"
s1.inspect          #=> "#<Klass:0x401b3a38 @str=\"Hi\">"
s2.inspect          #=> "#<Klass:0x401b3998 @str=\"Hi\">"

This method may have class-specific behavior. If so, that behavior will be documented under the # initialize_copymethod of the class.

VALUE
rb_obj_clone(obj)
    VALUE obj;
{
    VALUE clone;
    if (rb_special_const_p(obj)) {
        rb_raise(rb_eTypeError, "can't clone %s", rb_obj_classname(obj));
    }
    clone = rb_obj_alloc(rb_obj_class(obj));
    RBASIC(clone)->klass = rb_singleton_class_clone(obj);
    RBASIC(clone)->flags = (RBASIC(obj)->flags | FL_TEST(clone, FL_TAINT)) & ~(FL_FREEZE|FL_FINALIZE);
    init_copy(clone, obj);
    RBASIC(clone)->flags |= RBASIC(obj)->flags & FL_FREEZE;
    return clone;
}
cp()

Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY

ruby -run -e cp -- [OPTION] SOURCE DEST
-p          preserve file attributes if possible
-r          copy recursively
-v          verbose
# File lib/un.rb, line 68
def cp
  setup("pr") do |argv, options|
    cmd = "cp"
    cmd += "_r" if options.delete :r
    options[:preserve] = true if options.delete :p
    dest = argv.pop
    argv = argv[0] if argv.size == 1
    FileUtils.send cmd, argv, dest, options
  end
end
create_docfile(src)
# File ext/win32ole/extconf.rb, line 14
def create_docfile(src)
  open(File.expand_path($srcdir) + "/.document", "w") {|ofs|
    ofs.print src
  }
end
create_header(header = "extconf.h")

Generates a header file consisting of the various macro definitions generated by other methods such as #have_func and have_header. These are then wrapped in a custom ifndef based on the headerfile name, which defaults to 'extconf.h'.

For example:

# extconf.rb
require 'mkmf'
have_func('realpath')
have_header('sys/utime.h')
create_header
create_makefile('foo')

The above script would generate the following extconf.h file:

#ifndef EXTCONF_H
#define EXTCONF_H
#define HAVE_REALPATH 1
#define HAVE_SYS_UTIME_H 1
#endif

Given that the #create_header method generates a file based on definitions set earlier in your extconf.rb file, you will probably want to make this one of the last methods you call in your script.

# File lib/mkmf.rb, line 1120
def create_header(header = "extconf.h")
  message "creating %s\n", header
  sym = header.tr("a-z./\0055", "A-Z___")
  hdr = ["#ifndef #{sym}\n#define #{sym}\n"]
  for line in $defs
    case line
    when /^-D([^=]+)(?:=(.*))?/
      hdr << "#define #$1 #{$2 ? Shellwords.shellwords($2)[0] : 1}\n"
    when /^-U(.*)/
      hdr << "#undef #$1\n"
    end
  end
  hdr << "#endif\n"
  hdr = hdr.join
  unless (IO.read(header) == hdr rescue false)
    open(header, "w") do |hfile|
      hfile.write(hdr)
    end
  end
  $extconf_h = header
end
create_makefile(target, srcprefix = nil)

Generates the Makefile for your extension, passing along any options and preprocessor constants that you may have generated through other methods.

The targetname should correspond the name of the global function name defined within your C extension, minus the 'Init_'. For example, if your C extension is defined as 'Init_foo', then your target would simply be 'foo'.

If any '/' characters are present in the target name, only the last name is interpreted as the target name, and the rest are considered toplevel directory names, and the generated Makefile will be altered accordingly to follow that directory structure.

For example, if you pass 'test/foo' as a target name, your extension will be installed under the 'test' directory. This means that in order to load the file within a Ruby program later, that directory structure will have to be followed, e.g. “require 'test/foo'”.

The srcprefixshould be used when your source files are not in the same directory as your build script. This will not only eliminate the need for you to manually copy the source files into the same directory as your build script, but it also sets the proper target_prefix in the generated Makefile.

Setting the target_prefixwill, in turn, install the generated binary in a directory under your Config::CONFIG that mimics your local filesystem when you run 'make install'.

For example, given the following file tree:

ext/
   extconf.rb
   test/
      foo.c

And given the following code:

create_makefile('test/foo', 'test')

That will set the target_prefixin the generated Makefile to 'test'. That, in turn, will create the following file tree when installed via the 'make install' command:

/path/to/ruby/sitearchdir/test/foo.so

It is recommended that you use this approach to generate your makefiles, instead of copying files around manually, because some third party libraries may depend on the target_prefixbeing set properly.

The srcprefixargument can be used to override the default source directory, i.e. the current directory . It is included as part of the VPATH and added to the list of INCFLAGS.

# File lib/mkmf.rb, line 1422
def create_makefile(target, srcprefix = nil)
  $target = target
  libpath = $DEFLIBPATH|$LIBPATH
  message "creating Makefile\n"
  rm_f "conftest*"
  if CONFIG["DLEXT"] == $OBJEXT
    for lib in libs = $libs.split
      lib.sub!(/-l(.*)/, %Q"lib\\1.#{$LIBEXT}"%)
    end
    $defs.push(format("-DEXTLIB='%s'", libs.join(",")))
  end
  if target.include?('/')
    target_prefix, target = File.split(target)
    target_prefix[0,0] = '/'
  else
    target_prefix = ""
  end
  srcprefix ||= '$(srcdir)'
  Config::expand(srcdir = srcprefix.dup)
  if not $objs
    $objs = []
    srcs = Dir[File.join(srcdir, "*.{#{SRC_EXT.join(%q{,})}}")]
    for f in srcs
      obj = File.basename(f, ".*") << ".o"
      $objs.push(obj) unless $objs.index(obj)
    end
  elsif !(srcs = $srcs)
    srcs = $objs.collect {|obj| obj.sub(/\.o\z/, '.c')}
  end
  $srcs = srcs
  for i in $objs
    i.sub!(/\.o\z/, ".#{$OBJEXT}")
  end
  $objs = $objs.join(" ")
  target = nil if $objs == ""
  if target and EXPORT_PREFIX
    if File.exist?(File.join(srcdir, target + '.def'))
      deffile = "$(srcdir)/$(TARGET).def"
      unless EXPORT_PREFIX.empty?
        makedef = %Q{-pe "sub!(/^(?=\\w)/,'#{EXPORT_PREFIX}') unless 1../^EXPORTS$/i"}
      end
    else
      makedef = %Q{-e "puts 'EXPORTS', '#{EXPORT_PREFIX}Init_$(TARGET)'"}
    end
    if makedef
      $distcleanfiles << '$(DEFFILE)'
      origdef = deffile
      deffile = "$(TARGET)-$(arch).def"
    end
  end
  origdef ||= ''
  libpath = libpathflag(libpath)
  dllib = target ? "$(TARGET).#{CONFIG['DLEXT']}" : ""
  staticlib = target ? "$(TARGET).#$LIBEXT" : ""
  mfile = open("Makefile", "wb")
  mfile.print configuration(srcprefix)
  mfile.print "
libpath = #{($DEFLIBPATH|$LIBPATH).join(" ")}
LIBPATH = #{libpath}
DEFFILE = #{deffile}
CLEANFILES = #{$cleanfiles.join(' ')}
DISTCLEANFILES = #{$distcleanfiles.join(' ')}
extout = #{$extout}
extout_prefix = #{$extout_prefix}
target_prefix = #{target_prefix}
LOCAL_LIBS = #{$LOCAL_LIBS}
LIBS = #{$LIBRUBYARG} #{$libs} #{$LIBS}
SRCS = #{srcs.collect(&File.method(:basename)).join(' ')}
OBJS = #{$objs}
TARGET = #{target}
DLLIB = #{dllib}
EXTSTATIC = #{$static || ""}
STATIC_LIB = #{staticlib unless $static.nil?}
#{!$extout && defined?($installed_list) ? "INSTALLED_LIST = #{$installed_list}\n" : ""}
"
  install_dirs.each {|d| mfile.print("%-14s= %s\n" % d) if /^[[:upper:]]/ =~ d[0]}
  n = ($extout ? '$(RUBYARCHDIR)/' : '') + '$(TARGET).'
  mfile.print "
TARGET_SO     = #{($extout ? '$(RUBYARCHDIR)/' : '')}$(DLLIB)
CLEANLIBS     = #{n}#{CONFIG['DLEXT']} #{n}il? #{n}tds #{n}map
CLEANOBJS     = *.#{$OBJEXT} *.#{$LIBEXT} *.s[ol] *.pdb *.exp *.bak
all:            #{$extout ? "install" : target ? "$(DLLIB)" : "Makefile"}
static:         $(STATIC_LIB)#{$extout ? " install-rb" : ""}
"
  mfile.print CLEANINGS
  dirs = []
  mfile.print "install: install-so install-rb\n\n"
  sodir = (dir = "$(RUBYARCHDIR)").dup
  mfile.print("install-so: ")
  if target
    f = "$(DLLIB)"
    dest = "#{dir}/#{f}"
    mfile.puts dir, "install-so: #{dest}"
    unless $extout
      mfile.print "#{dest}: #{f}\n"
      if (sep = config_string('BUILD_FILE_SEPARATOR'))
        f.gsub!("/", sep)
        dir.gsub!("/", sep)
        sep = ":/="+sep
        f.gsub!(/(\$\(\w+)(\))/) {$1+sep+$2}
        f.gsub!(/(\$\{\w+)(\})/) {$1+sep+$2}
        dir.gsub!(/(\$\(\w+)(\))/) {$1+sep+$2}
        dir.gsub!(/(\$\{\w+)(\})/) {$1+sep+$2}
      end
      mfile.print "\t$(INSTALL_PROG) #{f} #{dir}\n"
      if defined?($installed_list)
        mfile.print "\t@echo #{dir}/#{File.basename(f)}>>$(INSTALLED_LIST)\n"
      end
    end
  else
    mfile.puts "Makefile"
  end
  mfile.print("install-rb: pre-install-rb install-rb-default\n")
  mfile.print("install-rb-default: pre-install-rb-default\n")
  mfile.print("pre-install-rb: Makefile\n")
  mfile.print("pre-install-rb-default: Makefile\n")
  for sfx, i in [["-default", [["lib/**/*.rb", "$(RUBYLIBDIR)", "lib"]]], ["", $INSTALLFILES]]
    files = install_files(mfile, i, nil, srcprefix) or next
    for dir, *files in files
      unless dirs.include?(dir)
        dirs << dir
        mfile.print "pre-install-rb#{sfx}: #{dir}\n"
      end
      files.each do |f|
        dest = "#{dir}/#{File.basename(f)}"
        mfile.print("install-rb#{sfx}: #{dest}\n")
        mfile.print("#{dest}: #{f} #{dir}\n\t$(#{$extout ? 'COPY' : 'INSTALL_DATA'}) ")
        sep = config_string('BUILD_FILE_SEPARATOR')
        if sep
          f = f.gsub("/", sep)
          sep = ":/="+sep
          f = f.gsub(/(\$\(\w+)(\))/) {$1+sep+$2}
          f = f.gsub(/(\$\{\w+)(\})/) {$1+sep+$2}
        else
          sep = ""
        end
        mfile.print("#{f} $(@D#{sep})\n")
        if defined?($installed_list) and !$extout
          mfile.print("\t@echo #{dest}>>$(INSTALLED_LIST)\n")
        end
      end
    end
  end
  dirs.unshift(sodir) if target and !dirs.include?(sodir)
  dirs.each {|dir| mfile.print "#{dir}:\n\t$(MAKEDIRS) $@\n"}
  mfile.print <<-SITEINSTALL
site-install: site-install-so site-install-rb
site-install-so: install-so
site-install-rb: install-rb
  SITEINSTALL
  return unless target
  mfile.puts SRC_EXT.collect {|ext| ".path.#{ext} = $(VPATH)"} if $nmake == b
  mfile.print ".SUFFIXES: .#{SRC_EXT.join(' .')} .#{$OBJEXT}\n"
  mfile.print "\n"
  CXX_EXT.each do |ext|
    COMPILE_RULES.each do |rule|
      mfile.printf(rule, ext, $OBJEXT)
      mfile.printf("\n\t%s\n\n", COMPILE_CXX)
    end
  end
  %w[c].each do |ext|
    COMPILE_RULES.each do |rule|
      mfile.printf(rule, ext, $OBJEXT)
      mfile.printf("\n\t%s\n\n", COMPILE_C)
    end
  end
  mfile.print "$(RUBYARCHDIR)/" if $extout
  mfile.print "$(DLLIB): "
  mfile.print "$(DEFFILE) " if makedef
  mfile.print "$(OBJS) Makefile\n"
  mfile.print "\t@-$(RM) $@\n"
  mfile.print "\t@-$(MAKEDIRS) $(@D)\n" if $extout
  link_so = LINK_SO.gsub(/^/, "\t")
  mfile.print link_so, "\n\n"
  unless $static.nil?
    mfile.print "$(STATIC_LIB): $(OBJS)\n\t"
    mfile.print "$(AR) #{config_string('ARFLAGS') || 'cru '}$@ $(OBJS)"
    config_string('RANLIB') do |ranlib|
      mfile.print "\n\t@-#{ranlib} $(DLLIB) 2> /dev/null || true"
    end
  end
  mfile.print "\n\n"
  if makedef
    mfile.print "$(DEFFILE): #{origdef}\n"
    mfile.print "\t$(RUBY) #{makedef} #{origdef} > $@\n\n"
  end
  depend = File.join(srcdir, "depend")
  if File.exist?(depend)
    suffixes = []
    depout = []
    open(depend, "r") do |dfile|
      mfile.printf "###\n"
      cont = implicit = nil
      impconv = proc do
        COMPILE_RULES.each {|rule| depout << (rule % implicit[0]) << implicit[1]}
        implicit = nil
      end
      ruleconv = proc do |line|
        if implicit
          if /\A\t/ =~ line
            implicit[1] << line
            next
          else
            impconv[]
          end
        end
        if m = /\A\.(\w+)\.(\w+)(?:\s*:)/.match(line)
          suffixes << m[1] << m[2]
          implicit = [[m[1], m[2]], [m.post_match]]
          next
        elsif RULE_SUBST and /\A(?!\s*\w+\s*=)[$\w][^#]*:/ =~ line
          line.gsub!(%r(\s)(?!\.)([^$(){}+=:\s\/\,]+)(?=\s|\z)") {$1 + RULE_SUBST % $2}
        end
        depout << line
      end
      while line = dfile.gets()
        line.gsub!(/\.o\b/, ".#{$OBJEXT}")
        line.gsub!(/\$\((?:hdr|top)dir\)\/config.h/, $config_h) if $config_h
        if /(?:^|[^\])(?:\\)*\$/ =~ line
          (cont ||= []) << line
          next
        elsif cont
          line = (cont << line).join
          cont = nil
        end
        ruleconv.call(line)
      end
      if cont
        ruleconv.call(cont.join)
      elsif implicit
        impconv.call
      end
    end
    unless suffixes.empty?
      mfile.print ".SUFFIXES: .", suffixes.uniq.join(" ."), "\n\n"
    end
    mfile.print "$(OBJS): $(RUBY_EXTCONF_H)\n\n" if $extconf_h
    mfile.print depout
  else
    headers = %w[ruby.h defines.h]
    if RULE_SUBST
      headers.each {|h| h.sub!(/.*/) {|*m| RULE_SUBST % m}}
    end
    headers << $config_h if $config_h
    headers << "$(RUBY_EXTCONF_H)" if $extconf_h
    mfile.print "$(OBJS): ", headers.join(' '), "\n"
  end
  $makefile_created = true
ensure
  mfile.close if mfile
end
create_win32ole_makefile()
# File ext/win32ole/extconf.rb, line 20
def create_win32ole_makefile
  if have_library("ole32") and
     have_library("oleaut32") and
     have_library("uuid") and
     have_library("user32") and
     have_library("kernel32") and
     have_library("advapi32") and
     have_header("windows.h")
    create_makefile("win32ole")
    create_docfile(SRCFILES)
  else
    create_docfile("")
  end
end
dclone()
# File lib/rexml/xpath_parser.rb, line 8
def dclone
  clone
end
default_handler(event, *args)
# File ext/win32ole/sample/ienavi.rb, line 14
def default_handler(event, *args)
  case event
  when "BeforeNavigate"
    puts "Now Navigate #{args[0]}..."
  end
end
dir_config(target, idefault=nil, ldefault=nil)

Sets a targetname that the user can then use to configure various 'with' options with on the command line by using that name. For example, if the target is set to “foo”, then the user could use the –with-foo-dir command line option.

You may pass along additional 'include' or 'lib' defaults via the idefaultand ldefaultparameters, respectively.

Note that #dir_config only adds to the list of places to search for libraries and include files. It does not link the libraries into your application.

# File lib/mkmf.rb, line 1153
def dir_config(target, idefault=nil, ldefault=nil)
  if dir = with_config(target + "-dir", (idefault unless ldefault))
    defaults = Array === dir ? dir : dir.split(File::PATH_SEPARATOR)
    idefault = ldefault = nil
  end
  idir = with_config(target + "-include", idefault)
  $arg_config.last[1] ||= "${#{target}-dir}/include"
  ldir = with_config(target + "-lib", ldefault)
  $arg_config.last[1] ||= "${#{target}-dir}/lib"
  idirs = idir ? Array === idir ? idir : idir.split(File::PATH_SEPARATOR) : []
  if defaults
    idirs.concat(defaults.collect {|dir| dir + "/include"})
    idir = ([idir] + idirs).compact.join(File::PATH_SEPARATOR)
  end
  unless idirs.empty?
    idirs.collect! {|dir| "-I" + dir}
    idirs -= Shellwords.shellwords($CPPFLAGS)
    unless idirs.empty?
      $CPPFLAGS = (idirs.quote << $CPPFLAGS).join(" ")
    end
  end
  ldirs = ldir ? Array === ldir ? ldir : ldir.split(File::PATH_SEPARATOR) : []
  if defaults
    ldirs.concat(defaults.collect {|dir| dir + "/lib"})
    ldir = ([ldir] + ldirs).compact.join(File::PATH_SEPARATOR)
  end
  $LIBPATH = ldirs | $LIBPATH
  [idir, ldir]
end
obj.display(port=$>) => nil

Prints objon the given port (default $>). Equivalent to:

def display(port=$>)
  port.write self
end

For example:

1.display
"cat".display
[ 4, 5, 6 ].display
puts

produces:

1cat456
static VALUE
rb_obj_display(argc, argv, self)
    int argc;
    VALUE *argv;
    VALUE self;
{
    VALUE out;
    if (rb_scan_args(argc, argv, "01", &out) == 0) {
        out = rb_stdout;
    }
    rb_io_write(out, self);
    return Qnil;
}
obj.dup → an_object

Produces a shallow copy of obj—the instance variables of objare copied, but not the objects they reference. dupcopies the tainted state of obj. See also the discussion under Object#clone. In general, clone and dupmay have different semantics in descendent classes. While cloneis used to duplicate an object, including its internal state, duptypically uses the class of the descendent object to create the new instance.

This method may have class-specific behavior. If so, that behavior will be documented under the # initialize_copymethod of the class.

VALUE
rb_obj_dup(obj)
    VALUE obj;
{
    VALUE dup;
    if (rb_special_const_p(obj)) {
        rb_raise(rb_eTypeError, "can't dup %s", rb_obj_classname(obj));
    }
    dup = rb_obj_alloc(rb_obj_class(obj));
    init_copy(dup, obj);
    return dup;
}
enable_config(config, *defaults)

Tests for the presence of an –enable- configor –disable- configoption. Returns true if the enable option is given, false if the disable option is given, and the default value otherwise.

This can be useful for adding custom definitions, such as debug information.

Example:

if enable_config("debug")
   $defs.push("-DOSSL_DEBUG") unless $defs.include? "-DOSSL_DEBUG"
end
# File lib/mkmf.rb, line 1082
def enable_config(config, *defaults)
  if arg_config("--enable-"+config)
    true
  elsif arg_config("--disable-"+config)
    false
  elsif block_given?
    yield(config, *defaults)
  else
    return *defaults
  end
end
obj.to_enum(method = :each, *args) obj.enum_for(method = :each, *args)

Returns Enumerable::Enumerator.new(self, method, *args).

e.g.:

str = "xyz"
enum = str.enum_for(:each_byte)
a = enum.map {|b| '%02x' % b } #=> ["78", "79", "7a"]
# protects an array from being modified
a = [1, 2, 3]
some_method(a.to_enum)
static VALUE
obj_to_enum(argc, argv, obj)
    int argc;
    VALUE *argv;
    VALUE obj;
{
    VALUE meth = sym_each;
    if (argc > 0) {
        --argc;
        meth = *argv++;
    }
    return rb_enumeratorize(obj, meth, argc, argv);
}
obj == other => true or false obj.equal?(other) => true or false obj.eql?(other) => true or false

Equality—At the Objectlevel, ==returns trueonly if objand otherare the same object. Typically, this method is overridden in descendent classes to provide class-specific meaning.

Unlike ==, the equal?method should never be overridden by subclasses: it is used to determine object identity (that is, a.equal?(b)iff ais the same object as b).

The eql?method returns trueif objand anObject have the same value. Used by Hashto test members for equality. For objects of class Object, eql?is synonymous with ==. Subclasses normally continue this tradition, but there are exceptions. Numerictypes, for example, perform type conversion across ==, but not across eql?, so:

1 == 1.0     #=> true
1.eql? 1.0   #=> false
static VALUE
rb_obj_equal(obj1, obj2)
    VALUE obj1, obj2;
{
    if (obj1 == obj2) return Qtrue;
    return Qfalse;
}
obj == other => true or false obj.equal?(other) => true or false obj.eql?(other) => true or false

Equality—At the Objectlevel, ==returns trueonly if objand otherare the same object. Typically, this method is overridden in descendent classes to provide class-specific meaning.

Unlike ==, the equal?method should never be overridden by subclasses: it is used to determine object identity (that is, a.equal?(b)iff ais the same object as b).

The eql?method returns trueif objand anObject have the same value. Used by Hashto test members for equality. For objects of class Object, eql?is synonymous with ==. Subclasses normally continue this tradition, but there are exceptions. Numerictypes, for example, perform type conversion across ==, but not across eql?, so:

1 == 1.0     #=> true
1.eql? 1.0   #=> false
static VALUE
rb_obj_equal(obj1, obj2)
    VALUE obj1, obj2;
{
    if (obj1 == obj2) return Qtrue;
    return Qfalse;
}
obj.extend(module, ...) => obj

Adds to objthe instance methods from each module given as a parameter.

module Mod
  def hello
    "Hello from Mod.\n"
  end
end
class Klass
  def hello
    "Hello from Klass.\n"
  end
end
k = Klass.new
k.hello         #=> "Hello from Klass.\n"
k.extend(Mod)   #=> #<Klass:0x401b3bc8>
k.hello         #=> "Hello from Mod.\n"
static VALUE
rb_obj_extend(argc, argv, obj)
    int argc;
    VALUE *argv;
    VALUE obj;
{
    int i;
    if (argc == 0) {
        rb_raise(rb_eArgError, "wrong number of arguments (0 for 1)");
    }
    for (i=0; i<argc; i++) Check_Type(argv[i], T_MODULE);
    while (argc--) {
        rb_funcall(argv[argc], rb_intern("extend_object"), 1, obj);
        rb_funcall(argv[argc], rb_intern("extended"), 1, obj);
    }
    return obj;
}
find_executable(bin, path = nil)

Searches for the executable binon path. The default path is your PATH environment variable. If that isn't defined, it will resort to searching /usr/local/bin, /usr/ucb, /usr/bin and /bin.

If found, it will return the full path, including the executable name, of where it was found.

Note that this method does not actually affect the generated Makefile.

# File lib/mkmf.rb, line 1021
def find_executable(bin, path = nil)
  checking_for checking_message(bin, path) do
    find_executable0(bin, path)
  end
end
find_header(header, *paths)

Instructs mkmf to search for the given headerin any of the pathsprovided, and returns whether or not it was found in those paths.

If the header is found then the path it was found on is added to the list of included directories that are sent to the compiler (via the -I switch).

# File lib/mkmf.rb, line 761
def find_header(header, *paths)
  message = checking_message(header, paths)
  header = cpp_include(header)
  checking_for message do
    if try_cpp(header)
      true
    else
      found = false
      paths.each do |dir|
        opt = "-I#{dir}".quote
        if try_cpp(header, opt)
          $INCFLAGS << " " << opt
          found = true
          break
        end
      end
      found
    end
  end
end
find_library(lib, func, *paths, &b)

Returns whether or not the entry point funccan be found within the library libin one of the paths specified, where pathsis an array of strings. If funcis nil , then the main() function is used as the entry point.

If libis found, then the path it was found on is added to the list of library paths searched and linked against.

# File lib/mkmf.rb, line 677
def find_library(lib, func, *paths, &b)
  func = "main" if !func or func.empty?
  lib = with_config(lib+'lib', lib)
  paths = paths.collect {|path| path.split(File::PATH_SEPARATOR)}.flatten
  checking_for "#{func}() in #{LIBARG%lib}" do
    libpath = $LIBPATH
    libs = append_library($libs, lib)
    begin
      until r = try_func(func, libs, &b) or paths.empty?
        $LIBPATH = libpath | [paths.shift]
      end
      if r
        $libs = libs
        libpath = nil
      end
    ensure
      $LIBPATH = libpath if libpath
    end
    r
  end
end
find_type(type, opt, *headers, &b)

Returns where the static type typeis defined.

You may also pass additional flags to optwhich are then passed along to the compiler.

See also have_type.

# File lib/mkmf.rb, line 851
def find_type(type, opt, *headers, &b)
  opt ||= ""
  fmt = "not found"
  def fmt.%(x)
    x ? x.respond_to?(:join) ? x.join(",") : x : self
  end
  checking_for checking_message(type, nil, opt), fmt do
    headers.find do |h|
      try_type(type, h, opt, &b)
    end
  end
end
obj.freeze => obj

Prevents further modifications to obj. A TypeError will be raised if modification is attempted. There is no way to unfreeze a frozen object. See also Object#frozen?.

a = [ "a", "b", "c" ]
a.freeze
a << "z"

produces:

prog.rb:3:in `<<': can't modify frozen array (TypeError)
 from prog.rb:3
VALUE
rb_obj_freeze(obj)
    VALUE obj;
{
    if (!OBJ_FROZEN(obj)) {
        if (rb_safe_level() >= 4 && !OBJ_TAINTED(obj)) {
            rb_raise(rb_eSecurityError, "Insecure: can't freeze object");
        }
        OBJ_FREEZE(obj);
    }
    return obj;
}
obj.frozen? => true or false

Returns the freeze status of obj.

a = [ "a", "b", "c" ]
a.freeze    #=> ["a", "b", "c"]
a.frozen?   #=> true
static VALUE
rb_obj_frozen_p(obj)
    VALUE obj;
{
    if (OBJ_FROZEN(obj)) return Qtrue;
    return Qfalse;
}
getopts(single_options, *options)

getopts is obsolete. Use GetoptLong.

# File lib/getopts.rb, line 24
def getopts(single_options, *options)
  boolopts = {}
  valopts = {}
  #
  # set defaults
  #
  single_options.scan(/.:?/) do |opt|
    if opt.size == 1
      boolopts[opt] = false
    else
      valopts[opt[0, 1]] = nil
    end
  end if single_options
  options.each do |arg|
    opt, val = arg.split(':', 2)
    if val
      valopts[opt] = val.empty? ? nil : val
    else
      boolopts[opt] = false
    end
  end
  #
  # scan
  #
  c = 0
  argv = ARGV
  while arg = argv.shift
    case arg
    when /\A--(.*)/
      if $1.empty?                      # xinit -- -bpp 24
        break
      end
      opt, val = $1.split('=', 2)
      if opt.size == 1
        argv.unshift arg
        return nil
      elsif valopts.key? opt            # imclean --src +trash
        valopts[opt] = val || argv.shift or return nil
      elsif boolopts.key? opt           # ruby --verbose
        boolopts[opt] = true
      else
        argv.unshift arg
        return nil
      end
      c += 1
    when /\A-(.+)/
      opts = $1
      until opts.empty?
        opt = opts.slice!(0, 1)
        if valopts.key? opt
          val = opts
          if val.empty?                        # ruby -e 'p $:'
            valopts[opt] = argv.shift or return nil
          else                         # cc -ohello ...
            valopts[opt] = val
          end
          c += 1
          break
        elsif boolopts.key? opt
          boolopts[opt] = true         # ruby -h
          c += 1
        else
          argv.unshift arg
          return nil
        end
      end
    else
      argv.unshift arg
      break
    end
  end
  #
  # set
  #
  $OPT = {}
  boolopts.each do |opt, val|
    $OPT[opt] = val
    sopt = opt.gsub(/[^A-Za-z0-9_]/, '_')
    eval "$OPT_#{sopt} = val"
  end
  valopts.each do |opt, val|
    $OPT[opt] = val
    sopt = opt.gsub(/[^A-Za-z0-9_]/, '_')
    eval "$OPT_#{sopt} = val"
  end
  c
end
obj.hash => fixnum

Generates a Fixnumhash value for this object. This function must have the property that a.eql?(b)implies a.hash == b.hash . The hash value is used by class Hash. Any hash value that exceeds the capacity of a Fixnumwill be truncated before being used.

VALUE
rb_obj_id(VALUE obj)
{
    /*
     *                32-bit VALUE space
     *          MSB ------------------------ LSB
     *  false   00000000000000000000000000000000
     *  true    00000000000000000000000000000010
     *  nil     00000000000000000000000000000100
     *  undef   00000000000000000000000000000110
     *  symbol  ssssssssssssssssssssssss00001110
     *  object  oooooooooooooooooooooooooooooo00        = 0 (mod sizeof(RVALUE))
     *  fixnum  fffffffffffffffffffffffffffffff1
     *
     *                    object_id space
     *                                       LSB
     *  false   00000000000000000000000000000000
     *  true    00000000000000000000000000000010
     *  nil     00000000000000000000000000000100
     *  undef   00000000000000000000000000000110
     *  symbol   000SSSSSSSSSSSSSSSSSSSSSSSSSSS0        S...S % A = 4 (S...S = s...s * A + 4)
     *  object   oooooooooooooooooooooooooooooo0        o...o % A = 0
     *  fixnum  fffffffffffffffffffffffffffffff1        bignum if required
     *
     *  where A = sizeof(RVALUE)/4
     *
     *  sizeof(RVALUE) is
     *  20 if 32-bit, double is 4-byte aligned
     *  24 if 32-bit, double is 8-byte aligned
     *  40 if 64-bit
     */
    if (TYPE(obj) == T_SYMBOL) {
        return (SYM2ID(obj) * sizeof(RVALUE) + (4 << 2)) | FIXNUM_FLAG;
    }
    if (SPECIAL_CONST_P(obj)) {
        return LONG2NUM((long)obj);
    }
    return (VALUE)((long)obj|FIXNUM_FLAG);
}
have_const(const, headers = nil, opt = "", &b)

Returns whether or not the constant constis defined. You may optionally pass the typeof constas [const, type], like as:

have_const(%w[PTHREAD_MUTEX_INITIALIZER pthread_mutex_t], "pthread.h")

You may also pass additional headersto check against in addition to the common header files, and additional flags to optwhich are then passed along to the compiler.

If found, a macro is passed as a preprocessor constant to the compiler using the type name, in uppercase, prepended with 'HAVE_CONST_'.

For example, if #have_const('foo') returned true, then the HAVE_CONST_FOO preprocessor macro would be passed to the compiler.

# File lib/mkmf.rb, line 896
def have_const(const, headers = nil, opt = "", &b)
  checking_for checking_message([*const].compact.join(' '), headers, opt) do
    try_const(const, headers, opt, &b)
  end
end
have_func(func, headers = nil, &b)

Returns whether or not the function funccan be found in the common header files, or within any headersthat you provide. If found, a macro is passed as a preprocessor constant to the compiler using the function name, in uppercase, prepended with 'HAVE_'.

For example, if #have_func('foo') returned true, then the HAVE_FOO preprocessor macro would be passed to the compiler.

# File lib/mkmf.rb, line 707
def have_func(func, headers = nil, &b)
  checking_for checking_message("#{func}()", headers) do
    if try_func(func, $libs, headers, &b)
      $defs.push(format("-DHAVE_%s", func.tr_cpp))
      true
    else
      false
    end
  end
end
have_header(header, &b)

Returns whether or not the given headerfile can be found on your system. If found, a macro is passed as a preprocessor constant to the compiler using the header file name, in uppercase, prepended with 'HAVE_'.

For example, if #have_header('foo.h') returned true, then the HAVE_FOO_H preprocessor macro would be passed to the compiler.

# File lib/mkmf.rb, line 744
def have_header(header, &b)
  checking_for header do
    if try_cpp(cpp_include(header), &b)
      $defs.push(format("-DHAVE_%s", header.tr("a-z./\0055", "A-Z___")))
      true
    else
      false
    end
  end
end
have_library(lib, func = nil, headers = nil, &b)

Returns whether or not the given entry point funccan be found within lib. If funcis nil, the 'main()' entry point is used by default. If found, it adds the library to list of libraries to be used when linking your extension.

If headersare provided, it will include those header files as the header files it looks in when searching for func.

The real name of the library to be linked can be altered by '–with-FOOlib' configuration option.

# File lib/mkmf.rb, line 652
def have_library(lib, func = nil, headers = nil, &b)
  func = "main" if !func or func.empty?
  lib = with_config(lib+'lib', lib)
  checking_for checking_message("#{func}()", LIBARG%lib) do
    if COMMON_LIBS.include?(lib)
      true
    else
      libs = append_library($libs, lib)
      if try_func(func, libs, headers, &b)
        $libs = libs
        true
      else
        false
      end
    end
  end
end
have_macro(macro, headers = nil, opt = "", &b)

Returns whether or not macrois defined either in the common header files or within any headersyou provide.

Any options you pass to optare passed along to the compiler.

# File lib/mkmf.rb, line 635
def have_macro(macro, headers = nil, opt = "", &b)
  checking_for checking_message(macro, headers, opt) do
    macro_defined?(macro, cpp_include(headers), opt, &b)
  end
end
have_struct_member(type, member, headers = nil, &b)

Returns whether or not the struct of type typecontains member. If it does not, or the struct type can't be found, then false is returned. You may optionally specify additional headersin which to look for the struct (in addition to the common header files).

If found, a macro is passed as a preprocessor constant to the compiler using the member name, in uppercase, prepended with 'HAVE_ST_'.

For example, if #have_struct_member('struct foo', 'bar') returned true, then the HAVE_ST_BAR preprocessor macro would be passed to the compiler.

# File lib/mkmf.rb, line 793
def have_struct_member(type, member, headers = nil, &b)
  checking_for checking_message("#{type}.#{member}", headers) do
    if try_compile("#{COMMON_HEADERS}
#{cpp_include(headers)}
/*top*/
int main() { return 0; }
int s = (char *)&((#{type}*)0)->#{member} - (char *)0;
", &b)
      $defs.push(format("-DHAVE_ST_%s", member.tr_cpp))
      true
    else
      false
    end
  end
end
have_type(type, headers = nil, opt = "", &b)

Returns whether or not the static type typeis defined. You may optionally pass additional headersto check against in addition to the common header files.

You may also pass additional flags to optwhich are then passed along to the compiler.

If found, a macro is passed as a preprocessor constant to the compiler using the type name, in uppercase, prepended with 'HAVE_TYPE_'.

For example, if #have_type('foo') returned true, then the HAVE_TYPE_FOO preprocessor macro would be passed to the compiler.

# File lib/mkmf.rb, line 838
def have_type(type, headers = nil, opt = "", &b)
  checking_for checking_message(type, headers, opt) do
    try_type(type, headers, opt, &b)
  end
end
have_var(var, headers = nil, &b)

Returns whether or not the variable varcan be found in the common header files, or within any headersthat you provide. If found, a macro is passed as a preprocessor constant to the compiler using the variable name, in uppercase, prepended with 'HAVE_'.

For example, if #have_var('foo') returned true, then the HAVE_FOO preprocessor macro would be passed to the compiler.

# File lib/mkmf.rb, line 726
def have_var(var, headers = nil, &b)
  checking_for checking_message(var, headers) do
    if try_var(var, headers, &b)
      $defs.push(format("-DHAVE_%s", var.tr_cpp))
      true
    else
      false
    end
  end
end
help()

Display help message.

ruby -run -e help [COMMAND]
# File lib/un.rb, line 222
def help
  setup do |argv,|
    all = argv.empty?
    open(__FILE__) do |me|
      while me.gets("##\n")
        if help = me.gets("\n\n")
          if all or argv.delete help[/-e \w+/].sub(/-e /, "")
            print help.gsub(/^# ?/, "")
          end
        end
      end
    end
  end
end
obj.id => fixnum

Soon-to-be deprecated version of Object#object_id.

VALUE
rb_obj_id_obsolete(obj)
    VALUE obj;
{
    rb_warn("Object#id will be deprecated; use Object#object_id");
    return rb_obj_id(obj);
}
obj.inspect => string

Returns a string containing a human-readable representation of obj. If not overridden, uses the to_smethod to generate the string.

[ 1, 2, 3..4, 'five' ].inspect   #=> "[1, 2, 3..4, \"five\"]"
Time.new.inspect                 #=> "Wed Apr 09 08:54:39 CDT 2003"
static VALUE
rb_obj_inspect(obj)
    VALUE obj;
{
    if (TYPE(obj) == T_OBJECT
        && ROBJECT(obj)->iv_tbl
        && ROBJECT(obj)->iv_tbl->num_entries > 0) {
        VALUE str;
        size_t len;
        const char *c = rb_obj_classname(obj);
        if (rb_inspecting_p(obj)) {
            len = strlen(c)+10+16+1;
            str = rb_str_new(0, len); /* 10:tags 16:addr 1:nul */
            snprintf(RSTRING(str)->ptr, len, "#<%s:0x%lx ...>", c, obj);
            RSTRING(str)->len = strlen(RSTRING(str)->ptr);
            return str;
        }
        len = strlen(c)+6+16+1;
        str = rb_str_new(0, len);     /* 6:tags 16:addr 1:nul */
        snprintf(RSTRING(str)->ptr, len, "-<%s:0x%lx", c, obj);
        RSTRING(str)->len = strlen(RSTRING(str)->ptr);
        return rb_protect_inspect(inspect_obj, obj, str);
    }
    return rb_funcall(obj, rb_intern("to_s"), 0, 0);
}
install()

Copy SOURCE to DEST.

ruby -run -e install -- [OPTION] SOURCE DEST
-p          apply access/modification times of SOURCE files to
            corresponding destination files
-m          set permission mode (as in chmod), instead of 0755
-v          verbose
# File lib/un.rb, line 177
def install
  setup("pm:") do |argv, options|
    options[:mode] = (mode = options.delete :m) ? mode.oct : 0755
    options[:preserve] = true if options.delete :p
    dest = argv.pop
    argv = argv[0] if argv.size == 1
    FileUtils.install argv, dest, options
  end
end
obj.instance_eval(string [, filename [, lineno]] ) => obj obj.instance_eval {| | block } => obj

Evaluates a string containing Ruby source code, or the given block, within the context of the receiver ( obj). In order to set the context, the variable selfis set to objwhile the code is executing, giving the code access to obj's instance variables. In the version of instance_evalthat takes a String, the optional second and third parameters supply a filename and starting line number that are used when reporting compilation errors.

class Klass
  def initialize
    @secret = 99
  end
end
k = Klass.new
k.instance_eval { @secret }   #=> 99
VALUE
rb_obj_instance_eval(argc, argv, self)
    int argc;
    VALUE *argv;
    VALUE self;
{
    VALUE klass;
    if (SPECIAL_CONST_P(self)) {
        klass = Qnil;
    }
    else {
        klass = rb_singleton_class(self);
    }
    return specific_eval(argc, argv, klass, self);
}
obj.instance_exec(arg...) {|var...| block } => obj

Executes the given block within the context of the receiver ( obj). In order to set the context, the variable selfis set to objwhile the code is executing, giving the code access to obj's instance variables. Arguments are passed as block parameters.

class KlassWithSecret
  def initialize
    @secret = 99
  end
end
k = KlassWithSecret.new
k.instance_exec(5) {|x| @secret+x }   #=> 104
VALUE
rb_obj_instance_exec(argc, argv, self)
    int argc;
    VALUE *argv;
    VALUE self;
{
    VALUE klass;
    if (SPECIAL_CONST_P(self)) {
        klass = Qnil;
    }
    else {
        klass = rb_singleton_class(self);
    }
    return yield_under(klass, self, rb_ary_new4(argc, argv));
}
obj.instance_of?(class) => true or false

Returns trueif objis an instance of the given class. See also Object#kind_of?.

VALUE
rb_obj_is_instance_of(obj, c)
    VALUE obj, c;
{
    switch (TYPE(c)) {
      case T_MODULE:
      case T_CLASS:
      case T_ICLASS:
        break;
      default:
        rb_raise(rb_eTypeError, "class or module required");
    }
    if (rb_obj_class(obj) == c) return Qtrue;
    return Qfalse;
}
obj.instance_variable_defined?(symbol) => true or false

Returns trueif the given instance variable is defined in obj.

class Fred
  def initialize(p1, p2)
    @a, @b = p1, p2
  end
end
fred = Fred.new('cat', 99)
fred.instance_variable_defined?(:@a)    #=> true
fred.instance_variable_defined?("@b")   #=> true
fred.instance_variable_defined?("@c")   #=> false
static VALUE
rb_obj_ivar_defined(obj, iv)
    VALUE obj, iv;
{
    ID id = rb_to_id(iv);
    if (!rb_is_instance_id(id)) {
        rb_name_error(id, "`%s' is not allowed as an instance variable name", rb_id2name(id));
    }
    return rb_ivar_defined(obj, id);
}
obj.instance_variable_get(symbol) => obj

Returns the value of the given instance variable, or nil if the instance variable is not set. The @part of the variable name should be included for regular instance variables. Throws a NameError exception if the supplied symbol is not valid as an instance variable name.

class Fred
  def initialize(p1, p2)
    @a, @b = p1, p2
  end
end
fred = Fred.new('cat', 99)
fred.instance_variable_get(:@a)    #=> "cat"
fred.instance_variable_get("@b")   #=> 99
static VALUE
rb_obj_ivar_get(obj, iv)
    VALUE obj, iv;
{
    ID id = rb_to_id(iv);
    if (!rb_is_instance_id(id)) {
        rb_name_error(id, "`%s' is not allowed as an instance variable name", rb_id2name(id));
    }
    return rb_ivar_get(obj, id);
}
obj.instance_variable_set(symbol, obj) => obj

Sets the instance variable names by symbolto object, thereby frustrating the efforts of the class's author to attempt to provide proper encapsulation. The variable did not have to exist prior to this call.

class Fred
  def initialize(p1, p2)
    @a, @b = p1, p2
  end
end
fred = Fred.new('cat', 99)
fred.instance_variable_set(:@a, 'dog')   #=> "dog"
fred.instance_variable_set(:@c, 'cat')   #=> "cat"
fred.inspect                             #=> "#<Fred:0x401b3da8 @a=\"dog\", @b=99, @c=\"cat\">"
static VALUE
rb_obj_ivar_set(obj, iv, val)
    VALUE obj, iv, val;
{
    ID id = rb_to_id(iv);
    if (!rb_is_instance_id(id)) {
        rb_name_error(id, "`%s' is not allowed as an instance variable name", rb_id2name(id));
    }
    return rb_ivar_set(obj, id, val);
}
obj.instance_variables => array

Returns an array of instance variable names for the receiver. Note that simply defining an accessor does not create the corresponding instance variable.

class Fred
  attr_accessor :a1
  def initialize
    @iv = 3
  end
end
Fred.new.instance_variables   #=> ["@iv"]
VALUE
rb_obj_instance_variables(obj)
    VALUE obj;
{
    VALUE ary;
    ary = rb_ary_new();
    switch (TYPE(obj)) {
      case T_OBJECT:
      case T_CLASS:
      case T_MODULE:
  if (ROBJECT(obj)->iv_tbl) {
      st_foreach_safe(ROBJECT(obj)->iv_tbl, ivar_i, ary);
  }
  break;
      default:
  if (!generic_iv_tbl) break;
  if (FL_TEST(obj, FL_EXIVAR) || rb_special_const_p(obj)) {
      st_data_t tbl;
      if (st_lookup(generic_iv_tbl, obj, &tbl)) {
    st_foreach_safe((st_table *)tbl, ivar_i, ary);
      }
  }
  break;
    }
    return ary;
}
obj.is_a?(class) => true or false obj.kind_of?(class) => true or false

Returns trueif classis the class of obj, or if classis one of the superclasses of objor modules included in obj.

module M;    end
class A
  include M
end
class B < A; end
class C < B; end
b = B.new
b.instance_of? A   #=> false
b.instance_of? B   #=> true
b.instance_of? C   #=> false
b.instance_of? M   #=> false
b.kind_of? A       #=> true
b.kind_of? B       #=> true
b.kind_of? C       #=> false
b.kind_of? M       #=> true
VALUE
rb_obj_is_kind_of(obj, c)
    VALUE obj, c;
{
    VALUE cl = CLASS_OF(obj);
    switch (TYPE(c)) {
      case T_MODULE:
      case T_CLASS:
      case T_ICLASS:
        break;
      default:
        rb_raise(rb_eTypeError, "class or module required");
    }
    while (cl) {
        if (cl == c || RCLASS(cl)->m_tbl == RCLASS(c)->m_tbl)
            return Qtrue;
        cl = RCLASS(cl)->super;
    }
    return Qfalse;
}
obj.is_a?(class) => true or false obj.kind_of?(class) => true or false

Returns trueif classis the class of obj, or if classis one of the superclasses of objor modules included in obj.

module M;    end
class A
  include M
end
class B < A; end
class C < B; end
b = B.new
b.instance_of? A   #=> false
b.instance_of? B   #=> true
b.instance_of? C   #=> false
b.instance_of? M   #=> false
b.kind_of? A       #=> true
b.kind_of? B       #=> true
b.kind_of? C       #=> false
b.kind_of? M       #=> true
VALUE
rb_obj_is_kind_of(obj, c)
    VALUE obj, c;
{
    VALUE cl = CLASS_OF(obj);
    switch (TYPE(c)) {
      case T_MODULE:
      case T_CLASS:
      case T_ICLASS:
        break;
      default:
        rb_raise(rb_eTypeError, "class or module required");
    }
    while (cl) {
        if (cl == c || RCLASS(cl)->m_tbl == RCLASS(c)->m_tbl)
            return Qtrue;
        cl = RCLASS(cl)->super;
    }
    return Qfalse;
}
listup(items)
# File ext/win32ole/sample/oledirs.rb, line 7
def listup(items)
#  items.each do |i|
  for i in items
    puts i.name
  end
end
ln()

Create a link to the specified TARGET with LINK_NAME.

ruby -run -e ln -- [OPTION] TARGET LINK_NAME
-s          make symbolic links instead of hard links
-f          remove existing destination files
-v          verbose
# File lib/un.rb, line 89
def ln
  setup("sf") do |argv, options|
    cmd = "ln"
    cmd += "_s" if options.delete :s
    options[:force] = true if options.delete :f
    dest = argv.pop
    argv = argv[0] if argv.size == 1
    FileUtils.send cmd, argv, dest, options
  end
end
obj.method(sym) => method

Looks up the named method as a receiver in obj, returning a Methodobject (or raising NameError). The Methodobject acts as a closure in obj's object instance, so instance variables and the value of selfremain available.

class Demo
  def initialize(n)
    @iv = n
  end
  def hello()
    "Hello, @iv = #{@iv}"
  end
end
k = Demo.new(99)
m = k.method(:hello)
m.call   #=> "Hello, @iv = 99"
l = Demo.new('Fred')
m = l.method("hello")
m.call   #=> "Hello, @iv = Fred"
VALUE
rb_obj_method(obj, vid)
    VALUE obj;
    VALUE vid;
{
    return mnew(CLASS_OF(obj), obj, rb_to_id(vid), rb_cMethod);
}
obj.methods => array

Returns a list of the names of methods publicly accessible in obj. This will include all the methods accessible in obj's ancestors.

class Klass
  def kMethod()
  end
end
k = Klass.new
k.methods[0..9]    #=> ["kMethod", "freeze", "nil?", "is_a?", 
                        "class", "instance_variable_set",
                         "methods", "extend", "__send__", "instance_eval"]
k.methods.length   #=> 42
static VALUE
rb_obj_methods(argc, argv, obj)
    int argc;
    VALUE *argv;
    VALUE obj;
{
  retry:
    if (argc == 0) {
        VALUE args[1];
        args[0] = Qtrue;
        return rb_class_instance_methods(1, args, CLASS_OF(obj));
    }
    else {
        VALUE recur;
        rb_scan_args(argc, argv, "1", &recur);
        if (RTEST(recur)) {
            argc = 0;
            goto retry;
        }
        return rb_obj_singleton_methods(argc, argv, obj);
    }
}
mkdir()

Create the DIR, if they do not already exist.

ruby -run -e mkdir -- [OPTION] DIR
-p          no error if existing, make parent directories as needed
-v          verbose
# File lib/un.rb, line 144
def mkdir
  setup("p") do |argv, options|
    cmd = "mkdir"
    cmd += "_p" if options.delete :p
    FileUtils.send cmd, argv, options
  end
end
mv()

Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.

ruby -run -e mv -- [OPTION] SOURCE DEST
-v          verbose
# File lib/un.rb, line 108
def mv
  setup do |argv, options|
    dest = argv.pop
    argv = argv[0] if argv.size == 1
    FileUtils.mv argv, dest, options
  end
end
navigate(url)
# File ext/win32ole/sample/ienavi.rb, line 5
def navigate(url)
  $urls << url
end
nil?()

call_seq:

nil.nil?               => true
<anything_else>.nil?   => false

Only the object nilresponds trueto nil?.

static VALUE
rb_false(obj)
    VALUE obj;
{
    return Qfalse;
}
obj.__id__ => fixnum obj.object_id => fixnum

Returns an integer identifier for obj. The same number will be returned on all calls to idfor a given object, and no two active objects will share an id. Object#object_idis a different concept from the :namenotation, which returns the symbol id of name. Replaces the deprecated Object#id.

VALUE
rb_obj_id(VALUE obj)
{
    /*
     *                32-bit VALUE space
     *          MSB ------------------------ LSB
     *  false   00000000000000000000000000000000
     *  true    00000000000000000000000000000010
     *  nil     00000000000000000000000000000100
     *  undef   00000000000000000000000000000110
     *  symbol  ssssssssssssssssssssssss00001110
     *  object  oooooooooooooooooooooooooooooo00        = 0 (mod sizeof(RVALUE))
     *  fixnum  fffffffffffffffffffffffffffffff1
     *
     *                    object_id space
     *                                       LSB
     *  false   00000000000000000000000000000000
     *  true    00000000000000000000000000000010
     *  nil     00000000000000000000000000000100
     *  undef   00000000000000000000000000000110
     *  symbol   000SSSSSSSSSSSSSSSSSSSSSSSSSSS0        S...S % A = 4 (S...S = s...s * A + 4)
     *  object   oooooooooooooooooooooooooooooo0        o...o % A = 0
     *  fixnum  fffffffffffffffffffffffffffffff1        bignum if required
     *
     *  where A = sizeof(RVALUE)/4
     *
     *  sizeof(RVALUE) is
     *  20 if 32-bit, double is 4-byte aligned
     *  24 if 32-bit, double is 8-byte aligned
     *  40 if 64-bit
     */
    if (TYPE(obj) == T_SYMBOL) {
        return (SYM2ID(obj) * sizeof(RVALUE) + (4 << 2)) | FIXNUM_FLAG;
    }
    if (SPECIAL_CONST_P(obj)) {
        return LONG2NUM((long)obj);
    }
    return (VALUE)((long)obj|FIXNUM_FLAG);
}
oletypelib_name(pat)
# File ext/win32ole/tests/oleserver.rb, line 2
def oletypelib_name(pat)
  WIN32OLE_TYPE.typelibs.each do |lib|
    return lib if pat =~ lib
  end
end
parseArgs(argc, nopt, single_opts, *opts)

parseArgs is obsolete. Use OptionParser instead.

# File lib/parsearg.rb, line 62
def parseArgs(argc, nopt, single_opts, *opts)
  if (noOptions = getopts(single_opts, *opts)) == nil
    printUsageAndExit()
  end
  if nopt
    ex = nil
    pos = 0
    for o in nopt.split(/[()|&]/)
      pos += o.length
      ex = setExpression(ex, o, nopt[pos])
      pos += 1
    end
    begin
      if !eval(ex)
        printUsageAndExit()
      end
    rescue
      print "Format Error!! : \"" + nopt + "\"\t[parseArgs]\n"
      exit!(-1)
    end
  end
  if ARGV.length < argc
    printUsageAndExit()
  end
  return noOptions
end
pretty_print(q)
# File lib/pp.rb, line 467
def pretty_print(q)
  q.text inspect
end
pretty_print_cycle(q)
# File lib/pp.rb, line 459
def pretty_print_cycle(q)
  q.text inspect
end
printUsageAndExit()
# File lib/parsearg.rb, line 19
def printUsageAndExit()
  if $USAGE
    eval($USAGE)
  end
  exit()
end
obj.private_methods(all=true) => array

Returns the list of private methods accessible to obj. If the allparameter is set to false, only those methods in the receiver will be listed.

static VALUE
rb_obj_private_methods(argc, argv, obj)
    int argc;
    VALUE *argv;
    VALUE obj;
{
    if (argc == 0) {            /* hack to stop warning */
        VALUE args[1];
        args[0] = Qtrue;
        return rb_class_private_instance_methods(1, args, CLASS_OF(obj));
    }
    return rb_class_private_instance_methods(argc, argv, CLASS_OF(obj));
}
obj.protected_methods(all=true) => array

Returns the list of protected methods accessible to obj. If the allparameter is set to false, only those methods in the receiver will be listed.

static VALUE
rb_obj_protected_methods(argc, argv, obj)
    int argc;
    VALUE *argv;
    VALUE obj;
{
    if (argc == 0) {            /* hack to stop warning */
        VALUE args[1];
        args[0] = Qtrue;
        return rb_class_protected_instance_methods(1, args, CLASS_OF(obj));
    }
    return rb_class_protected_instance_methods(argc, argv, CLASS_OF(obj));
}
obj.public_methods(all=true) => array

Returns the list of public methods accessible to obj. If the allparameter is set to false, only those methods in the receiver will be listed.

static VALUE
rb_obj_public_methods(argc, argv, obj)
    int argc;
    VALUE *argv;
    VALUE obj;
{
    if (argc == 0) {            /* hack to stop warning */
        VALUE args[1];
        args[0] = Qtrue;
        return rb_class_public_instance_methods(1, args, CLASS_OF(obj));
    }
    return rb_class_public_instance_methods(argc, argv, CLASS_OF(obj));
}
obj.respond_to?(symbol, include_private=false) => true or false

Returns true> if objresponds to the given method. Private methods are included in the search only if the optional second parameter evaluates to true.

static VALUE
obj_respond_to(argc, argv, obj)
    int argc;
    VALUE *argv;
    VALUE obj;
{
    VALUE mid, priv;
    ID id;
    rb_scan_args(argc, argv, "11", &mid, &priv);
    id = rb_to_id(mid);
    if (rb_method_boundp(CLASS_OF(obj), id, !RTEST(priv))) {
        return Qtrue;
    }
    return Qfalse;
}
rm()

Remove the FILE

ruby -run -e rm -- [OPTION] FILE
-f          ignore nonexistent files
-r          remove the contents of directories recursively
-v          verbose
# File lib/un.rb, line 126
def rm
  setup("fr") do |argv, options|
    cmd = "rm"
    cmd += "_r" if options.delete :r
    options[:force] = true if options.delete :f
    FileUtils.send cmd, argv, options
  end
end
rmdir()

Remove the DIR.

ruby -run -e rmdir -- [OPTION] DIR
-v          verbose
# File lib/un.rb, line 160
def rmdir
  setup do |argv, options|
    FileUtils.rmdir argv, options
  end
end
obj.send(symbol [, args...]) => obj obj.__send__(symbol [, args...]) => obj

Invokes the method identified by symbol, passing it any arguments specified. You can use __send__if the name send clashes with an existing method in obj.

class Klass
  def hello(*args)
    "Hello " + args.join(' ')
  end
end
k = Klass.new
k.send :hello, "gentle", "readers"   #=> "Hello gentle readers"
static VALUE
rb_f_send(argc, argv, recv)
    int argc;
    VALUE *argv;
    VALUE recv;
{
    VALUE vid;
    if (argc == 0) rb_raise(rb_eArgError, "no method name given");
    vid = *argv++; argc--;
    PUSH_ITER(rb_block_given_p()?ITER_PRE:ITER_NOT);
    vid = rb_call(CLASS_OF(recv), recv, rb_to_id(vid), argc, argv, 1, Qundef);
    POP_ITER();
    return vid;
}
setExpression(ex, opt, op)
# File lib/parsearg.rb, line 44
def setExpression(ex, opt, op)
  if !op
    ex = sprintf("%s$OPT_%s", ex, opt)
    return ex
  end
  case op.chr
  when "(", ")"
    ex = setParenthesis(ex, opt, op.chr)
  when "|", "&"
    ex = setOrAnd(ex, opt, op.chr)
  else
    return nil
  end
  return ex
end
setOrAnd(ex, opt, c)
# File lib/parsearg.rb, line 35
def setOrAnd(ex, opt, c)
  if opt != ""
    ex = sprintf("%s$OPT_%s %s%s ", ex, opt, c, c)
  else
    ex = sprintf("%s %s%s ", ex, c, c)
  end
  return ex
end
setParenthesis(ex, opt, c)
# File lib/parsearg.rb, line 26
def setParenthesis(ex, opt, c)
  if opt != ""
    ex = sprintf("%s$OPT_%s%s", ex, opt, c)
  else
    ex = sprintf("%s%s", ex, c)
  end
  return ex
end
setup(options = "")
# File lib/un.rb, line 32
def setup(options = "")
  ARGV.map! do |x|
    case x
    when /^-/
      x.delete "^-#{options}v"
    when /[*?\[{]/
      Dir[x]
    else
      x
    end
  end
  ARGV.flatten!
  ARGV.delete_if{|x| x == "-"}
  opt_hash = {}
  OptionParser.new do |o|
    options.scan(/.:?/) do |s|
      o.on("-" + s.tr(":", " ")) do |val|
        opt_hash[s.delete(":").intern] = val
      end
    end
    o.on("-v") do opt_hash[:verbose] = true end
    o.parse!
  end
  yield ARGV, opt_hash
end
obj.singleton_methods(all=true) => array

Returns an array of the names of singleton methods for obj. If the optional allparameter is true, the list will include methods in modules included in obj.

module Other
  def three() end
end
class Single
  def Single.four() end
end
a = Single.new
def a.one()
end
class << a
  include Other
  def two()
  end
end
Single.singleton_methods    #=> ["four"]
a.singleton_methods(false)  #=> ["two", "one"]
a.singleton_methods         #=> ["two", "one", "three"]
VALUE
rb_obj_singleton_methods(argc, argv, obj)
    int argc;
    VALUE *argv;
    VALUE obj;
{
    VALUE recur, ary, klass;
    st_table *list;
    rb_scan_args(argc, argv, "01", &recur);
    if (argc == 0) {
  recur = Qtrue;
    }
    klass = CLASS_OF(obj);
    list = st_init_numtable();
    if (klass && FL_TEST(klass, FL_SINGLETON)) {
  st_foreach(RCLASS(klass)->m_tbl, method_entry, (st_data_t)list);
  klass = RCLASS(klass)->super;
    }
    if (RTEST(recur)) {
  while (klass && (FL_TEST(klass, FL_SINGLETON) || TYPE(klass) == T_ICLASS)) {
      st_foreach(RCLASS(klass)->m_tbl, method_entry, (st_data_t)list);
      klass = RCLASS(klass)->super;
  }
    }
    ary = rb_ary_new();
    st_foreach(list, ins_methods_i, ary);
    st_free_table(list);
    return ary;
}
stop_msg_loop()
# File ext/win32ole/sample/ienavi.rb, line 9
def stop_msg_loop
  puts "Now Stop IE..."
  $LOOP = FALSE;
end
sysread(io, size)

cgi_runner.rb – CGI launcher.

Author: IPR – Internet Programming with Ruby – writers Copyright © 2000 TAKAHASHI Masayoshi, GOTOU YUUZOU Copyright © 2002 Internet Programming with Ruby writers. All rights reserved.

$IPR: cgi_runner.rb,v 1.9 2002/09/25 11:33:15 gotoyuzo Exp $

# File lib/webrick/httpservlet/cgi_runner.rb, line 11
def sysread(io, size)
  buf = ""
  while size > 0
    tmp = io.sysread(size)
    buf << tmp
    size -= tmp.size
  end
  return buf
end
obj.taint → obj

Marks objas tainted—if the $SAFElevel is set appropriately, many method calls which might alter the running programs environment will refuse to accept tainted strings.

VALUE
rb_obj_taint(obj)
    VALUE obj;
{
    rb_secure(4);
    if (!OBJ_TAINTED(obj)) {
        if (OBJ_FROZEN(obj)) {
            rb_error_frozen("object");
        }
        OBJ_TAINT(obj);
    }
    return obj;
}
obj.tainted? => true or false

Returns trueif the object is tainted.

VALUE
rb_obj_tainted(obj)
    VALUE obj;
{
    if (OBJ_TAINTED(obj))
        return Qtrue;
    return Qfalse;
}
obj.tap{|x|...} => obj

Yields xto the block, and then returns x. The primary purpose of this method is to “tap into” a method chain, in order to perform operations on intermediate results within the chain.

(1..10).tap {
  |x| puts "original: #{x.inspect}"
}.to_a.tap {
  |x| puts "array: #{x.inspect}"
}.select {|x| x%2==0}.tap {
  |x| puts "evens: #{x.inspect}"
}.map {|x| x*x}.tap {
  |x| puts "squares: #{x.inspect}"
}
VALUE
rb_obj_tap(obj)
    VALUE obj;
{
    rb_yield(obj);
    return obj;
}
obj.to_a → anArray

Returns an array representation of obj. For objects of class Objectand others that don't explicitly override the method, the return value is an array containing self. However, this latter behavior will soon be obsolete.

self.to_a       #=> -:1: warning: default `to_a' will be obsolete
"hello".to_a    #=> ["hello"]
Time.new.to_a   #=> [39, 54, 8, 9, 4, 2003, 3, 99, true, "CDT"]
static VALUE
rb_any_to_a(obj)
    VALUE obj;
{
    rb_warn("default `to_a' will be obsolete");
    return rb_ary_new3(1, obj);
}
obj.to_enum(method = :each, *args) obj.enum_for(method = :each, *args)

Returns Enumerable::Enumerator.new(self, method, *args).

e.g.:

str = "xyz"
enum = str.enum_for(:each_byte)
a = enum.map {|b| '%02x' % b } #=> ["78", "79", "7a"]
# protects an array from being modified
a = [1, 2, 3]
some_method(a.to_enum)
static VALUE
obj_to_enum(argc, argv, obj)
    int argc;
    VALUE *argv;
    VALUE obj;
{
    VALUE meth = sym_each;
    if (argc > 0) {
        --argc;
        meth = *argv++;
    }
    return rb_enumeratorize(obj, meth, argc, argv);
}
obj.to_s => string

Returns a string representing obj. The default to_s prints the object's class and an encoding of the object id. As a special case, the top-level object that is the initial execution context of Ruby programs returns “main.''

VALUE
rb_any_to_s(obj)
    VALUE obj;
{
    const char *cname = rb_obj_classname(obj);
    size_t len;
    VALUE str;
    len = strlen(cname)+6+16;
    str = rb_str_new(0, len); /* 6:tags 16:addr */
    snprintf(RSTRING(str)->ptr, len+1, "#<%s:0x%lx>", cname, obj);
    RSTRING(str)->len = strlen(RSTRING(str)->ptr);
    if (OBJ_TAINTED(obj)) OBJ_TAINT(str);
    return str;
}
to_yaml( opts = {} )
# File lib/yaml/rubytypes.rb, line 14
def to_yaml( opts = {} )
        YAML::quick_emit( self, opts ) do |out|
    out.map( taguri, to_yaml_style ) do |map|
                        to_yaml_properties.each do |m|
            map.add( m[1..-1], instance_variable_get( m ) )
        end
    end
end
end
to_yaml_properties()
# File lib/yaml/rubytypes.rb, line 13
def to_yaml_properties; instance_variables.sort; end
to_yaml_style()
# File lib/yaml/rubytypes.rb, line 12
def to_yaml_style; end
touch()

Update the access and modification times of each FILE to the current time.

ruby -run -e touch -- [OPTION] FILE
-v          verbose
# File lib/un.rb, line 210
def touch
  setup do |argv, options|
    FileUtils.touch argv, options
  end
end
try_const(const, headers = nil, opt = "", &b)
# File lib/mkmf.rb, line 864
def try_const(const, headers = nil, opt = "", &b)
  const, type = *const
  if try_compile("#{COMMON_HEADERS}
#{cpp_include(headers)}
/*top*/
typedef #{type || 'int'} conftest_type;
conftest_type conftestval = #{type ? '' : '(int)'}#{const};
", opt, &b)
    $defs.push(format("-DHAVE_CONST_%s", const.tr_cpp))
    true
  else
    false
  end
end
try_type(type, headers = nil, opt = "", &b)
# File lib/mkmf.rb, line 810
def try_type(type, headers = nil, opt = "", &b)
  if try_compile("#{COMMON_HEADERS}
#{cpp_include(headers)}
/*top*/
typedef #{type} conftest_type;
int conftestval[sizeof(conftest_type)?1:-1];
", opt, &b)
    $defs.push(format("-DHAVE_TYPE_%s", type.tr_cpp))
    true
  else
    false
  end
end
obj.type => class

Deprecated synonym for Object#class.

VALUE
rb_obj_type(obj)
    VALUE obj;
{
    rb_warn("Object#type is deprecated; use Object#class");
    return rb_class_real(CLASS_OF(obj));
}
obj.untaint => obj

Removes the taint from obj.

VALUE
rb_obj_untaint(obj)
    VALUE obj;
{
    rb_secure(3);
    if (OBJ_TAINTED(obj)) {
        if (OBJ_FROZEN(obj)) {
            rb_error_frozen("object");
        }
        FL_UNSET(obj, FL_TAINT);
    }
    return obj;
}
with_config(config, *defaults)

Tests for the presence of a –with- configor –without- configoption. Returns true if the with option is given, false if the without option is given, and the default value otherwise.

This can be useful for adding custom definitions, such as debug information.

Example:

if with_config("debug")
   $defs.push("-DOSSL_DEBUG") unless $defs.include? "-DOSSL_DEBUG"
end
# File lib/mkmf.rb, line 1049
def with_config(config, *defaults)
  config = config.sub(/^--with[-_]/, '')
  val = arg_config("--with-"+config) do
    if arg_config("--without-"+config)
      false
    elsif block_given?
      yield(config, *defaults)
    else
      break *defaults
    end
  end
  case val
  when "yes"
    true
  when "no"
    false
  else
    val
  end
end
xmp(exps, bind = nil)
# File lib/irb/xmp.rb, line 81
def xmp(exps, bind = nil)
  bind = IRB::Frame.top(1) unless bind
  xmp = XMP.new(bind)
  xmp.puts exps
  xmp
end