Class: Magick::Enum
Direct Known Subclasses
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Method: Enum#<=> Purpose: Support Comparable module in Enum Returns: -1, 0, 1, or nil Notes: Enums must be instances of the same class to be equal.
-
#===(other) ⇒ Object
Method: Enum#=== Purpose: “Case equal” operator for Enum Returns: true or false Notes: Yes, I know “case equal” is a misnomer.
-
#initialize(sym, val) ⇒ Object
constructor
Method: Enum#initialize Purpose: Initialize a new Enum instance.
-
#to_i ⇒ Object
Method: Enum#to_i Purpose: Return the value of an enum.
-
#to_s ⇒ Object
Method: Enum#to_s Purpose: Return the name of an enum.
Constructor Details
#initialize(sym, val) ⇒ Object
Method: Enum#initialize Purpose: Initialize a new Enum instance
100 101 102 103 104 105 106 107 108 109 110 |
# File 'ext/RMagick/rmenum.c', line 100
VALUE
Enum_initialize(VALUE self, VALUE sym, VALUE val)
{
MagickEnum *magick_enum;
Data_Get_Struct(self, MagickEnum, magick_enum);
magick_enum->id = rb_to_id(sym); /* convert symbol to ID */
magick_enum->val = NUM2INT(val);
return self;
}
|
Instance Method Details
#<=>(other) ⇒ Object
Method: Enum#<=> Purpose: Support Comparable module in Enum Returns: -1, 0, 1, or nil Notes: Enums must be instances of the same class to be equal.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'ext/RMagick/rmenum.c', line 133
VALUE
Enum_spaceship(VALUE self, VALUE other)
{
MagickEnum *this, *that;
Data_Get_Struct(self, MagickEnum, this);
Data_Get_Struct(other, MagickEnum, that);
if (this->val > that->val)
{
return INT2FIX(1);
}
else if (this->val < that->val)
{
return INT2FIX(-1);
}
// Values are equal, check class.
return rb_funcall(CLASS_OF(self), rm_ID_spaceship, 1, CLASS_OF(other));
}
|
#===(other) ⇒ Object
Method: Enum#=== Purpose: “Case equal” operator for Enum Returns: true or false Notes: Yes, I know “case equal” is a misnomer.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'ext/RMagick/rmenum.c', line 80
VALUE
Enum_case_eq(VALUE self, VALUE other)
{
MagickEnum *this, *that;
if (CLASS_OF(self) == CLASS_OF(other))
{
Data_Get_Struct(self, MagickEnum, this);
Data_Get_Struct(other, MagickEnum, that);
return this->val == that->val ? Qtrue : Qfalse;
}
return Qfalse;
}
|
#to_i ⇒ Object
Method: Enum#to_i Purpose: Return the value of an enum
117 118 119 120 121 122 123 124 |
# File 'ext/RMagick/rmenum.c', line 117
VALUE
Enum_to_i(VALUE self)
{
MagickEnum *magick_enum;
Data_Get_Struct(self, MagickEnum, magick_enum);
return INT2NUM(magick_enum->val);
}
|
#to_s ⇒ Object
Method: Enum#to_s Purpose: Return the name of an enum
160 161 162 163 164 165 166 167 |
# File 'ext/RMagick/rmenum.c', line 160
VALUE
Enum_to_s(VALUE self)
{
MagickEnum *magick_enum;
Data_Get_Struct(self, MagickEnum, magick_enum);
return rb_str_new2(rb_id2name(magick_enum->id));
}
|