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 list of public methods accessible to obj. If the all parameter is set to false
, only those methods in the receiver will be listed.
Similar to method, searches public method only.
Returns the number of bits of the value of int
.
“Number of bits” means the bit position of the highest bit which is different from the sign bit (where the least significant bit has bit position 1). If there is no such bit (zero or minus one), zero is returned.
I.e. this method returns ceil(log2(int < 0 ? -int : int+1)).
(-2**1000-1).bit_length #=> 1001 (-2**1000).bit_length #=> 1000 (-2**1000+1).bit_length #=> 1000 (-2**12-1).bit_length #=> 13 (-2**12).bit_length #=> 12 (-2**12+1).bit_length #=> 12 -0x101.bit_length #=> 9 -0x100.bit_length #=> 8 -0xff.bit_length #=> 8 -2.bit_length #=> 1 -1.bit_length #=> 0 0.bit_length #=> 0 1.bit_length #=> 1 0xff.bit_length #=> 8 0x100.bit_length #=> 9 (2**12-1).bit_length #=> 12 (2**12).bit_length #=> 13 (2**12+1).bit_length #=> 13 (2**1000-1).bit_length #=> 1000 (2**1000).bit_length #=> 1001 (2**1000+1).bit_length #=> 1001
This method can be used to detect overflow in Array#pack
as follows:
if n.bit_length < 32 [n].pack("l") # no overflow else raise "overflow" end
Returns a copy of str with leading prefix
deleted.
"hello".delete_prefix("hel") #=> "lo" "hello".delete_prefix("llo") #=> "hello"
Returns a copy of str with trailing suffix
deleted.
"hello".delete_suffix("llo") #=> "he" "hello".delete_suffix("hel") #=> "hello"
Deletes leading prefix
from str, returning nil
if no change was made.
"hello".delete_prefix!("hel") #=> "lo" "hello".delete_prefix!("llo") #=> nil
Deletes trailing suffix
from str, returning nil
if no change was made.
"hello".delete_suffix!("llo") #=> "he" "hello".delete_suffix!("hel") #=> nil
Passes the Integer
ordinal of each character in str, also known as a codepoint when applied to Unicode strings to the given block. For encodings other than UTF-8/UTF-16(BE|LE)/UTF-32(BE|LE), values are directly derived from the binary representation of each character.
If no block is given, an enumerator is returned instead.
"hello\u0639".each_codepoint {|c| print c, ' ' }
produces:
104 101 108 108 111 1593
Returns true
if the named file is readable by the real user and group id of this process. See access(3).
Note that some OS-level security features may cause this to return true even though the file is not readable by the real user/group.
If file_name is readable by others, returns an integer representing the file permission bits of file_name. Returns nil
otherwise. The meaning of the bits is platform dependent; on Unix systems, see stat(2)
.
file_name can be an IO
object.
File.world_readable?("/etc/passwd") #=> 420 m = File.world_readable?("/etc/passwd") sprintf("%o", m) #=> "644"
Returns true
if the named file is writable by the real user and group id of this process. See access(3).
Note that some OS-level security features may cause this to return true even though the file is not writable by the real user/group.
If file_name is writable by others, returns an integer representing the file permission bits of file_name. Returns nil
otherwise. The meaning of the bits is platform dependent; on Unix systems, see stat(2)
.
file_name can be an IO
object.
File.world_writable?("/tmp") #=> 511 m = File.world_writable?("/tmp") sprintf("%o", m) #=> "777"
Returns true
if the named file is executable by the real user and group id of this process. See access(3).
Windows does not support execute permissions separately from read permissions. On Windows, a file is only considered executable if it ends in .bat, .cmd, .com, or .exe.
Note that some OS-level security features may cause this to return true even though the file is not executable by the real user/group.
Returns default external encoding.
The default external encoding is used by default for strings created from the following locations:
File
data read from disk
While strings created from these locations will have this encoding, the encoding may not be valid. Be sure to check String#valid_encoding?
.
File
data written to disk will be transcoded to the default external encoding when written.
The default external encoding is initialized by the locale or -E option.
Sets default external encoding. You should not set Encoding::default_external
in ruby code as strings created before changing the value may have a different encoding from strings created after the value was changed., instead you should use ruby -E
to invoke ruby with the correct default_external.
See Encoding::default_external
for information on how the default external encoding is used.
Returns default internal encoding. Strings will be transcoded to the default internal encoding in the following places if the default internal encoding is not nil:
File
data read from disk
Strings returned from Readline
Strings returned from SDBM
Values from ENV
Values in ARGV including $PROGRAM_NAME
Additionally String#encode
and String#encode!
use the default internal encoding if no encoding is given.
The script encoding (__ENCODING__), not default_internal
, is used as the encoding of created strings.
Encoding::default_internal
is initialized by the source file’s internal_encoding or -E option.
Sets default internal encoding or removes default internal encoding when passed nil. You should not set Encoding::default_internal
in ruby code as strings created before changing the value may have a different encoding from strings created after the change. Instead you should use ruby -E
to invoke ruby with the correct default_internal.
See Encoding::default_internal
for information on how the default internal encoding is used.
Returns the locale charmap name. It returns nil if no appropriate information.
Debian GNU/Linux LANG=C Encoding.locale_charmap #=> "ANSI_X3.4-1968" LANG=ja_JP.EUC-JP Encoding.locale_charmap #=> "EUC-JP" SunOS 5 LANG=C Encoding.locale_charmap #=> "646" LANG=ja Encoding.locale_charmap #=> "eucJP"
The result is highly platform dependent. So Encoding.find(Encoding.locale_charmap)
may cause an error. If you need some encoding object even for unknown locale, Encoding.find
(“locale”) can be used.
Return a list of the local variable names defined where this NameError
exception was raised.
Internal use only.
The BigDecimal.double_fig
class method returns the number of digits a Float
number is allowed to have. The result depends upon the CPU and OS in use.
Returns true if the given year is a leap year of the proleptic Gregorian calendar.
Date.gregorian_leap?(1900) #=> false Date.gregorian_leap?(2000) #=> true
Deletes all entries for which the code block returns true. Returns self.