Returns true
if the real and effective group IDs of a process may be exchanged on the current platform.
Check if --yjit-stats
is used.
Return a hash for statistics generated for the --yjit-stats
command line option. Return nil
when option is not passed or unavailable. If a symbol argument is provided, return only the value for the named stat. If any other type is provided, raises TypeError
.
foo => bar ^^^^^^^^^^
def foo(*bar); end
^^^^
def foo(*); end
^
A shareable constant.
foo => bar ^^^^^^^^^^
def foo(*bar); end
^^^^
def foo(*); end
^
A shareable constant.
Calls the given block with each successive grapheme cluster from self
(see Unicode Grapheme Cluster Boundaries); returns self
:
s = "\u0061\u0308-pqr-\u0062\u0308-xyz-\u0063\u0308" # => "ä-pqr-b̈-xyz-c̈" s.each_grapheme_cluster {|gc| print gc, ' ' }
Output:
ä - p q r - b̈ - x y z - c̈
Returns an enumerator if no block is given.
Returns the value of the given instance variable, or nil if the instance variable is not set. The @
part of the variable name should be included for regular instance variables. Throws a NameError
exception if the supplied symbol is not valid as an instance variable name. String
arguments are converted to symbols.
class Fred def initialize(p1, p2) @a, @b = p1, p2 end end fred = Fred.new('cat', 99) fred.instance_variable_get(:@a) #=> "cat" fred.instance_variable_get("@b") #=> 99
Sets the instance variable named by symbol to the given object. This may circumvent the encapsulation intended by the author of the class, so it should be used with care. The variable does not have to exist prior to this call. If the instance variable name is passed as a string, that string is converted to a symbol.
class Fred def initialize(p1, p2) @a, @b = p1, p2 end end fred = Fred.new('cat', 99) fred.instance_variable_set(:@a, 'dog') #=> "dog" fred.instance_variable_set(:@c, 'cat') #=> "cat" fred.inspect #=> "#<Fred:0x401b3da8 @a=\"dog\", @b=99, @c=\"cat\">"
Returns true
if the given instance variable is defined in obj. String
arguments are converted to symbols.
class Fred def initialize(p1, p2) @a, @b = p1, p2 end end fred = Fred.new('cat', 99) fred.instance_variable_defined?(:@a) #=> true fred.instance_variable_defined?("@b") #=> true fred.instance_variable_defined?("@c") #=> false
Defines a public singleton method in the receiver. The method parameter can be a Proc
, a Method
or an UnboundMethod
object. If a block is specified, it is used as the method body. If a block or a method has parameters, they’re used as method parameters.
class A class << self def class_name to_s end end end A.define_singleton_method(:who_am_i) do "I am: #{class_name}" end A.who_am_i # ==> "I am: A" guy = "Bob" guy.define_singleton_method(:hello) { "#{self}: Hello there!" } guy.hello #=> "Bob: Hello there!" chris = "Chris" chris.define_singleton_method(:greet) {|greeting| "#{greeting}, I'm Chris!" } chris.greet("Hi") #=> "Hi, I'm Chris!"
Sets the temporary name of the module. This name is reflected in introspection of the module and the values that are related to it, such as instances, constants, and methods.
The name should be nil
or a non-empty string that is not a valid constant path (to avoid confusing between permanent and temporary names).
The method can be useful to distinguish dynamically generated classes and modules without assigning them to constants.
If the module is given a permanent name by assigning it to a constant, the temporary name is discarded. A temporary name can’t be assigned to modules that have a permanent name.
If the given name is nil
, the module becomes anonymous again.
Example:
m = Module.new # => #<Module:0x0000000102c68f38> m.name #=> nil m.set_temporary_name("fake_name") # => fake_name m.name #=> "fake_name" m.set_temporary_name(nil) # => #<Module:0x0000000102c68f38> m.name #=> nil c = Class.new c.set_temporary_name("MyClass(with description)") c.new # => #<MyClass(with description):0x0....> c::M = m c::M.name #=> "MyClass(with description)::M" # Assigning to a constant replaces the name with a permanent one C = c C.name #=> "C" C::M.name #=> "C::M" c.new # => #<C:0x0....>
Returns a list of the public instance methods defined in mod. If the optional parameter is false
, the methods of any ancestors are not included.
Returns a list of the protected instance methods defined in mod. If the optional parameter is false
, the methods of any ancestors are not included.