Results for: "module_function"

Copy a LocalVariableTargetNode node

Copy a LocalVariableWriteNode node

Get the subject’s key identifier from the subjectKeyIdentifier exteension, as described in RFC5280 Section 4.2.1.2.

Returns the binary String key identifier or nil or raises ASN1::ASN1Error.

Deletes an element from self, per the given Integer index.

When index is non-negative, deletes the element at offset index:

a = [:foo, 'bar', 2]
a.delete_at(1) # => "bar"
a # => [:foo, 2]

If index is too large, returns nil.

When index is negative, counts backward from the end of the array:

a = [:foo, 'bar', 2]
a.delete_at(-2) # => "bar"
a # => [:foo, 2]

If index is too small (far from zero), returns nil.

Removes each element in self for which the block returns a truthy value; returns self:

a = [:foo, 'bar', 2, 'bat']
a.delete_if {|element| element.to_s.start_with?('b') } # => [:foo, 2]

Returns a new Enumerator if no block given:

a = [:foo, 'bar', 2]
a.delete_if # => #<Enumerator: [:foo, "bar", 2]:delete_if>

Returns a new Array containing zero or more leading elements of self; does not modify self.

With a block given, calls the block with each successive element of self; stops if the block returns false or nil; returns a new Array containing those elements for which the block returned a truthy value:

a = [0, 1, 2, 3, 4, 5]
a.take_while {|element| element < 3 } # => [0, 1, 2]
a.take_while {|element| true } # => [0, 1, 2, 3, 4, 5]
a # => [0, 1, 2, 3, 4, 5]

With no block given, returns a new Enumerator:

[0, 1].take_while # => #<Enumerator: [0, 1]:take_while>

Returns a new Array containing zero or more trailing elements of self; does not modify self.

With a block given, calls the block with each successive element of self; stops if the block returns false or nil; returns a new Array omitting those elements for which the block returned a truthy value:

a = [0, 1, 2, 3, 4, 5]
a.drop_while {|element| element < 3 } # => [3, 4, 5]

With no block given, returns a new Enumerator:

[0, 1].drop_while # => # => #<Enumerator: [0, 1]:drop_while>

Returns the number of bits of the value of self, which is the bit position of the highest-order bit that 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), returns zero.

This method returns ceil(log2(self < 0 ? -self : self + 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

For Integer n, this method can be used to detect overflow in Array#pack:

if n.bit_length < 32
  [n].pack('l') # No overflow.
else
  raise 'Overflow'
end

Imports methods from modules. Unlike Module#include, Refinement#import_methods copies methods and adds them into the refinement, so the refinement is activated in the imported methods.

Note that due to method copying, only methods defined in Ruby code can be imported.

module StrUtils
  def indent(level)
    ' ' * level + self
  end
end

module M
  refine String do
    import_methods StrUtils
  end
end

using M
"foo".indent(3)
#=> "   foo"

module M
  refine String do
    import_methods Enumerable
    # Can't import method which is not defined with Ruby code: Enumerable#drop
  end
end

Returns a copy of self with leading substring prefix removed:

'hello'.delete_prefix('hel')      # => "lo"
'hello'.delete_prefix('llo')      # => "hello"
'тест'.delete_prefix('те')        # => "ст"
'こんにちは'.delete_prefix('こん')  # => "にちは"

Related: String#delete_prefix!, String#delete_suffix.

Returns a copy of self with trailing substring suffix removed:

'hello'.delete_suffix('llo')      # => "he"
'hello'.delete_suffix('hel')      # => "hello"
'тест'.delete_suffix('ст')        # => "те"
'こんにちは'.delete_suffix('ちは')  # => "こんに"

Related: String#delete_suffix!, String#delete_prefix.

Like String#delete_prefix, except that self is modified in place. Returns self if the prefix is removed, nil otherwise.

Like String#delete_suffix, except that self is modified in place. Returns self if the suffix is removed, nil otherwise.

Calls the given block with each successive codepoint from self; each codepoint is the integer value for a character; returns self:

'hello'.each_codepoint {|codepoint| print codepoint, ' ' }
print "\n"
'тест'.each_codepoint {|codepoint| print codepoint, ' ' }
print "\n"
'こんにちは'.each_codepoint {|codepoint| print codepoint, ' ' }
print "\n"

Output:

104 101 108 108 111
1090 1077 1089 1090
12371 12435 12395 12385 12399

Returns an enumerator if no block is given.

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:

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, if default_internal is not nil.

The default external encoding is initialized by the -E option. If -E isn’t set, it is initialized to UTF-8 on Windows and the locale on other operating systems.

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:

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 with -E option or nil otherwise.

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.

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.

Search took: 7ms  ·  Total Results: 4789