NAME

Sidef::Object::Object

DESCRIPTION

This class is the base class for all Sidef objects. It provides fundamental methods for object introspection, cloning, method manipulation, output, and smart matching.

SYNOPSIS

var obj = Object()

INHERITS

Inherits methods from:

* Sidef::Object::Convert

METHODS

!~

a !~ b

Returns the negation of the smart match operator. Returns true if a does not smart match b.

&&

a && b

Logical AND operator. Returns b if a is true, otherwise returns a.

:

a : b

Creates a Pair object from a and b. This is a deprecated alias for the pair operator.

\\

a \\ b

Defined-OR operator. Returns b if a is defined, otherwise returns a.

^

a ^ b

Logical XOR operator. Returns true if exactly one of a or b is true, otherwise returns false.

|>

a |> b

Pipeline operator. Passes a as the first argument to function or method b. If b is an array, the first element is used as the function and the remaining elements as additional arguments. If b is a string, it is treated as a method name to call on a.

||

a || b

Logical OR operator. Returns a if a is true, otherwise returns b.

~~

a ~~ b

Smart match operator. Performs context-sensitive comparison between a and b based on their types:

  • Two undefined values: returns true

  • Object ~~ TypeName: returns true if object's type is a subclass of TypeName

  • String ~~ RangeString: returns true if string is contained in range

  • Number ~~ RangeNumber: returns true if number is contained in range

  • Array ~~ Array: returns true if arrays are equal

  • Array ~~ Regex: returns true if any element matches the regex

  • Array ~~ Hash: returns true if hash contains all array elements as keys

  • Array ~~ Any: returns true if array contains the value

  • Hash ~~ Array: returns true if array contains all hash keys

  • Hash ~~ Hash: returns true if hashes are equal

  • Hash ~~ Regex: returns true if any key matches the regex

  • Hash ~~ Any: returns true if hash contains the key

  • Regex ~~ Array: returns true if any element matches the regex

  • Regex ~~ Hash: returns true if any key matches the regex

  • Regex ~~ Any: returns true if regex matches the value

  • Any ~~ Block: calls the block with the value and returns the result

Aliases: smartmatch

a ⫶ b

Creates a NamedParam object from a (the name) and b (the value). Uses the Triple Colon Operator (U+2AF6).

a : b

Creates a Pair object from a and b. Uses the Fullwidth Colon (U+FF1A).

alias_method

self. alias_method(old, new)

Creates an alias new for the existing method old on the object's class. Dies if the method old does not exist. Returns the object.

bless

obj.bless(arg)

Blesses arg into the class of obj and returns the blessed reference.

class

obj.class

Returns the short class name of the object (the part after the last ::). For example, Sidef::Types::Number::Number would return "Number".

clone

obj.clone

Returns a shallow copy of the object. For hash-based objects, creates a new hash with the same key-value pairs. For array-based objects, creates a new array with the same elements.

dclone

self.dclone

Returns a deep copy of the object, recursively cloning all nested hash and array structures. Handles circular references by tracking already-cloned objects.

Aliases: deep_clone

def_method

self.def_method(name, block)

Defines a new method with the given name on the object's class. The block will be called with the object and any arguments when the method is invoked. Returns the object.

dump

self.dump

Returns a string representation of the object suitable for debugging. For hash-based objects, includes all key-value pairs in the format ClassName(key: value, ...). Handles circular references.

interpolate

self. interpolate

Creates a new object of the same class by joining the provided arguments into a string. Used for string interpolation.

is_a

self.is_a(obj)

Returns true if the object is an instance of obj or inherits from obj, otherwise returns false.

Aliases: is_an, kind_of

is_object

self.is_object

Returns true if the value is an instantiated object (a reference), otherwise returns false.

is_typename

self.is_typename

Returns true if the value is a typename (not an instantiated object), otherwise returns false.

lazy

self.lazy

Returns a Lazy object wrapping the current object. The lazy object defers method calls until the result is actually needed.

method

self.method(method, *args)

Returns a LazyMethod object that, when called, will invoke the named method on the object with the given args. Useful for creating method references with bound arguments.

methods

self.methods(*args)

Returns a Hash of all public methods available on the object. Each value is a LazyMethod object bound to the object with the given args.

new

self.new

Creates and returns a new empty Object instance.

parent_classes

obj.parent_classes

Returns an Array of all parent classes (superclasses) that the object's class inherits from, recursively traversing the inheritance hierarchy.

print

self.print

Prints the object to standard output without a trailing newline. Returns true on success, false on failure.

ref

obj.ref

Returns the full class name (package name) of the object as a String. For example, Sidef::Types::Number::Number.

refaddr

self.refaddr

Returns a Number representing the memory address of the object reference. Useful for comparing object identity.

Aliases: object_id

reftype

self. reftype

Returns a String representing the underlying reference type of the object (e.g., "HASH", "ARRAY").

Aliases: object_type

respond_to

self.respond_to(method)

Returns true if the object has a method with the given name, otherwise returns false.

say

self.say

Prints the object to standard output followed by a newline. Returns true on success, false on failure.

Aliases: println

undef_method

self. undef_method(name)

Removes the method with the given name from the object's class. Returns the object.