Results for: "module_function"

Removes all elements and returns self.

set = Set[1, 'c', :s]             #=> #<Set: {1, "c", :s}>
set.clear                         #=> #<Set: {}>
set                               #=> #<Set: {}>

Deletes the given object from the set and returns self. Use subtract to delete many items at once.

Deletes the given object from the set and returns self. If the object is not in the set, returns nil.

Returns the number of members.

Customer = Struct.new(:name, :address, :zip)
joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
joe.size #=> 3

Equivalent to self.to_s.length; see String#length.

Returns clean pathname of self with consecutive slashes and useless dots removed. The filesystem is not accessed.

If consider_symlink is true, then a more conservative algorithm is used to avoid breaking symbolic linkages. This may retain more .. entries than absolutely necessary, but without accessing the filesystem, this can’t be avoided.

See Pathname#realpath.

See FileTest.executable?.

See FileTest.file?.

See FileTest.readable?.

See FileTest.writable?.

Removes a file or directory, using File.unlink if self is a file, or Dir.unlink as necessary.

Tokenizes the Ruby program and returns an array of an array, which is formatted like [[lineno, column], type, token, state]. The filename argument is mostly ignored. By default, this method does not handle syntax errors in src, use the raise_errors keyword to raise a SyntaxError for an error in src.

require 'ripper'
require 'pp'

pp Ripper.lex("def m(a) nil end")
#=> [[[1,  0], :on_kw,     "def", FNAME    ],
     [[1,  3], :on_sp,     " ",   FNAME    ],
     [[1,  4], :on_ident,  "m",   ENDFN    ],
     [[1,  5], :on_lparen, "(",   BEG|LABEL],
     [[1,  6], :on_ident,  "a",   ARG      ],
     [[1,  7], :on_rparen, ")",   ENDFN    ],
     [[1,  8], :on_sp,     " ",   BEG      ],
     [[1,  9], :on_kw,     "nil", END      ],
     [[1, 12], :on_sp,     " ",   END      ],
     [[1, 13], :on_kw,     "end", END      ]]

Returns nil. Just for compatibility to IO.

Returns the size of the buffer string.

Returns the default value for the given key. The returned value will be determined either by the default proc or by the default value. See Hash Default.

With no argument, returns the current default value:

h = {}
h.default # => nil

If key is given, returns the default value for key, regardless of whether that key exists:

h = Hash.new { |hash, key| hash[key] = "No key #{key}"}
h[:foo] = "Hello"
h.default(:foo) # => "No key foo"

Sets the default value to value; returns value:

h = {}
h.default # => nil
h.default = false # => false
h.default # => false

See Hash Default.

Returns the count of entries in self:

{foo: 0, bar: 1, baz: 2}.length # => 3

If an entry for the given key is found, deletes the entry and returns its associated value; otherwise returns nil or calls the given block.

With no block given and key found, deletes the entry and returns its value:

h = {foo: 0, bar: 1, baz: 2}
h.delete(:bar) # => 1
h # => {foo: 0, baz: 2}

With no block given and key not found, returns nil.

With a block given and key found, ignores the block, deletes the entry, and returns its value:

h = {foo: 0, bar: 1, baz: 2}
h.delete(:baz) { |key| raise 'Will never happen'} # => 2
h # => {foo: 0, bar: 1}

With a block given and key not found, calls the block and returns the block’s return value:

h = {foo: 0, bar: 1, baz: 2}
h.delete(:nosuch) { |key| "Key #{key} not found" } # => "Key nosuch not found"
h # => {foo: 0, bar: 1, baz: 2}

Related: see Methods for Deleting.

Removes all entries from self; returns emptied self.

Related: see Methods for Deleting.

Deletes the environment variable with name if it exists and returns its value:

ENV['foo'] = '0'
ENV.delete('foo') # => '0'

If a block is not given and the named environment variable does not exist, returns nil.

If a block given and the environment variable does not exist, yields name to the block and returns the value of the block:

ENV.delete('foo') { |name| name * 2 } # => "foofoo"

If a block given and the environment variable exists, deletes the environment variable and returns its value (ignoring the block):

ENV['foo'] = '0'
ENV.delete('foo') { |name| raise 'ignored' } # => "0"

Raises an exception if name is invalid. See Invalid Names and Values.

Removes every environment variable; returns ENV:

ENV.replace('foo' => '0', 'bar' => '1')
ENV.size # => 2
ENV.clear # => ENV
ENV.size # => 0

Returns the count of environment variables:

ENV.replace('foo' => '0', 'bar' => '1')
ENV.length # => 2
ENV.size # => 2

Raises TypeError, because ENV is a singleton object. Use to_h to get a copy of ENV data as a hash.

Returns an integer representing the numeric file descriptor for the current file. Raises an ArgumentError if there isn’t a current file.

ARGF.fileno    #=> 3

Returns the current filename. “-” is returned when the current file is STDIN.

For example:

$ echo "foo" > foo
$ echo "bar" > bar
$ echo "glark" > glark

$ ruby argf.rb foo bar glark

ARGF.filename  #=> "foo"
ARGF.read(5)   #=> "foo\nb"
ARGF.filename  #=> "bar"
ARGF.skip
ARGF.filename  #=> "glark"
Search took: 3ms  ·  Total Results: 3346