Returns the name of the method.
Returns the parameter information of this method.
def foo(bar); end method(:foo).parameters #=> [[:req, :bar]] def foo(bar, baz, bat, &blk); end method(:foo).parameters #=> [[:req, :bar], [:req, :baz], [:req, :bat], [:block, :blk]] def foo(bar, *args); end method(:foo).parameters #=> [[:req, :bar], [:rest, :args]] def foo(bar, baz, *args, &blk); end method(:foo).parameters #=> [[:req, :bar], [:req, :baz], [:rest, :args], [:block, :blk]]
Path of the file being run
Returns the system information obtained by uname system call.
The return value is a hash which has 5 keys at least:
:sysname, :nodename, :release, :version, :machine
Example:
require 'etc' require 'pp' pp Etc.uname #=> {:sysname=>"Linux", # :nodename=>"boron", # :release=>"2.6.18-6-xen-686", # :version=>"#1 SMP Thu Nov 5 19:54:42 UTC 2009", # :machine=>"i686"}
Retrieve the PathSupport
object that RubyGems uses to lookup files.
Initialize the filesystem paths to use from env
. env
is a hash-like object (typically ENV
) that is queried for ‘GEM_HOME’, ‘GEM_PATH’, and ‘GEM_SPEC_CACHE’ Keys for the env
hash should be Strings, and values of the hash should be Strings or nil
.
Convert signal number to signal name. Returns nil
if the signo is an invalid signal number.
Signal.trap("INT") { |signo| puts Signal.signame(signo) } Process.kill("INT", 0)
produces:
INT
Returns the namespace URL, if defined, or nil otherwise
e = Element.new("el") e.add_namespace("ns", "http://url") e.add_attribute("ns:a", "b") e.add_attribute("nsx:a", "c") e.attribute("ns:a").namespace # => "http://url" e.attribute("nsx:a").namespace # => nil
Evaluates to the URI
for a prefix, or the empty string if no such namespace is declared for this element. Evaluates recursively for ancestors. Returns the default namespace, if there is one.
the prefix to search for. If not supplied, returns the default namespace if one exists
the namespace URI
as a String, or nil if no such namespace exists. If the namespace is undefined, returns an empty string
doc = Document.new("<a xmlns='1' xmlns:y='2'><b/><c xmlns:z='3'/></a>") b = doc.elements['//b'] b.namespace # -> '1' b.namespace("y") # -> '2'
Returns the class for the given object
.
class A def foo ObjectSpace::trace_object_allocations do obj = Object.new p "#{ObjectSpace::allocation_class_path(obj)}" end end end A.new.foo #=> "Class"
See ::trace_object_allocations
for more information and examples.
When invoked with a block, yields all repeated combinations of length n
of elements from the array and then returns the array itself.
The implementation makes no guarantees about the order in which the repeated combinations are yielded.
If no block is given, an Enumerator
is returned instead.
Examples:
a = [1, 2, 3] a.repeated_combination(1).to_a #=> [[1], [2], [3]] a.repeated_combination(2).to_a #=> [[1,1],[1,2],[1,3],[2,2],[2,3],[3,3]] a.repeated_combination(3).to_a #=> [[1,1,1],[1,1,2],[1,1,3],[1,2,2],[1,2,3], # [1,3,3],[2,2,2],[2,2,3],[2,3,3],[3,3,3]] a.repeated_combination(4).to_a #=> [[1,1,1,1],[1,1,1,2],[1,1,1,3],[1,1,2,2],[1,1,2,3], # [1,1,3,3],[1,2,2,2],[1,2,2,3],[1,2,3,3],[1,3,3,3], # [2,2,2,2],[2,2,2,3],[2,2,3,3],[2,3,3,3],[3,3,3,3]] a.repeated_combination(0).to_a #=> [[]] # one combination of length 0
Returns the list of private methods accessible to obj. If the all parameter is set to false
, only those methods in the receiver will be listed.
Returns the path parameter passed to dir’s constructor.
d = Dir.new("..") d.path #=> ".."
Converts a pathname to an absolute pathname. Relative paths are referenced from the current working directory of the process unless dir_string is given, in which case it will be used as the starting point. If the given pathname starts with a “~
” it is NOT expanded, it is treated as a normal directory name.
File.absolute_path("~oracle/bin") #=> "<relative_path>/~oracle/bin"
Returns the pathname used to create file as a string. Does not normalize the name.
File.new("testfile").path #=> "testfile" File.new("/tmp/../tmp/xxx", "w").path #=> "/tmp/../tmp/xxx"
Returns the list of available encoding names.
Encoding.name_list #=> ["US-ASCII", "ASCII-8BIT", "UTF-8", "ISO-8859-1", "Shift_JIS", "EUC-JP", "Windows-31J", "BINARY", "CP932", "eucJP"]
Returns a hash representing information about named captures of rxp.
A key of the hash is a name of the named captures. A value of the hash is an array which is list of indexes of corresponding named captures.
/(?<foo>.)(?<bar>.)/.named_captures #=> {"foo"=>[1], "bar"=>[2]} /(?<foo>.)(?<foo>.)/.named_captures #=> {"foo"=>[1, 2]}
If there are no named captures, an empty hash is returned.
/(.)(.)/.named_captures #=> {}
Returns the socket path as a string.
Addrinfo.unix("/tmp/sock").unix_path #=> "/tmp/sock"