Returns the index of the last object in self
==
to obj
.
If a block is given instead of an argument, returns the index of the first object for which the block returns true
, starting from the last object.
Returns nil
if no match is found.
See also Array#index
.
If neither block nor argument is given, an Enumerator
is returned instead.
a = [ "a", "b", "b", "b", "c" ] a.rindex("b") #=> 3 a.rindex("z") #=> nil a.rindex { |x| x == "b" } #=> 3
Returns the index of the last occurrence of the given substring or pattern (regexp) in str. Returns nil
if not found. If the second parameter is present, it specifies the position in the string to end the search—characters beyond this point will not be considered.
"hello".rindex('e') #=> 1 "hello".rindex('l') #=> 3 "hello".rindex('a') #=> nil "hello".rindex(?e) #=> 1 "hello".rindex(/[aeiou]/, -2) #=> 1
Returns a copy of str with leading and trailing whitespace removed.
Whitespace is defined as any of the following characters: null, horizontal tab, line feed, vertical tab, form feed, carriage return, space.
" hello ".strip #=> "hello" "\tgoodbye\r\n".strip #=> "goodbye" "\x00\t\n\v\f\r ".strip #=> ""
Returns a copy of str with leading whitespace removed. See also String#rstrip
and String#strip
.
Refer to strip
for the definition of whitespace.
" hello ".lstrip #=> "hello " "hello".lstrip #=> "hello"
Returns a copy of str with trailing whitespace removed. See also String#lstrip
and String#strip
.
Refer to strip
for the definition of whitespace.
" hello ".rstrip #=> " hello" "hello".rstrip #=> "hello"
Removes leading and trailing whitespace from str. Returns nil
if str was not altered.
Refer to strip
for the definition of whitespace.
Removes leading whitespace from str, returning nil
if no change was made. See also String#rstrip!
and String#strip!
.
Refer to strip
for the definition of whitespace.
" hello ".lstrip #=> "hello " "hello".lstrip! #=> nil
Removes trailing whitespace from str, returning nil
if no change was made. See also String#lstrip!
and String#strip!
.
Refer to strip
for the definition of whitespace.
" hello ".rstrip #=> " hello" "hello".rstrip! #=> nil
Returns the current fiber. You need to require 'fiber'
before using this method. If you are not running in the context of a fiber this method will return the root fiber.
Returns an array containing all of the filenames in the given directory. Will raise a SystemCallError
if the named directory doesn’t exist.
The optional enc argument specifies the encoding of the directory. If not specified, the filesystem encoding is used.
Dir.entries("testdir") #=> [".", "..", "config.h", "main.rb"]
Returns true
if the named file is writable by the effective user and group id of this process. See eaccess(3).
With no arguments, sets the default visibility for subsequently defined methods to private. With arguments, sets the named methods to have private visibility. String arguments are converted to symbols.
module Mod def a() end def b() end private def c() end private :a end Mod.private_instance_methods #=> [:a, :c]
Returns true if self
is a prime number, else returns false.
Returns true if the date is Thursday.
Returns true if the date is Friday.
Returns true if the date is Saturday.
Retunrs true if the date is on or after the day of calendar reform.
Date.new(1582,10,15).gregorian? #=> true (Date.new(1582,10,15) - 1).gregorian? #=> false
This method is equivalent to new_start
(Date::GREGORIAN
).
Returns the hour of the day (0..23) for time.
t = Time.now #=> 2007-11-19 08:26:20 -0600 t.hour #=> 8
Returns true
if time represents Thursday.
t = Time.local(1995, 12, 21) #=> 1995-12-21 00:00:00 -0600 p t.thursday? #=> true
Returns true
if time represents Friday.
t = Time.local(1987, 12, 18) #=> 1987-12-18 00:00:00 -0600 t.friday? #=> true
Returns true
if time represents Saturday.
t = Time.local(2006, 6, 10) #=> 2006-06-10 00:00:00 -0500 t.saturday? #=> true