Class: Magick::Enum
Direct Known Subclasses
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Support Comparable module in Enum.
-
#===(other) ⇒ Object
“Case equal” operator for Enum.
-
#initialize(sym, val) ⇒ Object
constructor
Initialize a new Enum instance.
-
#to_i ⇒ Object
Return the value of an enum.
-
#to_s ⇒ Object
Return the name of an enum.
Constructor Details
#initialize(sym, val) ⇒ Object
Initialize a new Enum instance.
Ruby usage:
- @verbatim Enum#initialize(sym,val) @endverbatim
132 133 134 135 136 137 138 139 140 141 142 |
# File 'ext/RMagick/rmenum.c', line 132
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
Support Comparable module in Enum.
Ruby usage:
- @verbatim Enum#<=> @endverbatim
Notes:
- Enums must be instances of the same class to be equal.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'ext/RMagick/rmenum.c', line 177
VALUE
Enum_spaceship(VALUE self, VALUE other)
{
MagickEnum *this, *that;
if(CLASS_OF(self) != CLASS_OF(other)) {
return Qnil;
}
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);
}
return INT2FIX(0);
}
|
#===(other) ⇒ Object
“Case equal” operator for Enum.
Ruby usage:
- @verbatim Enum#=== @endverbatim
Notes:
- Yes, I know "case equal" is a misnomer.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'ext/RMagick/rmenum.c', line 105
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
Return the value of an enum.
Ruby usage:
- @verbatim Enum#to_i @endverbatim
154 155 156 157 158 159 160 161 |
# File 'ext/RMagick/rmenum.c', line 154
VALUE
Enum_to_i(VALUE self)
{
MagickEnum *magick_enum;
Data_Get_Struct(self, MagickEnum, magick_enum);
return INT2NUM(magick_enum->val);
}
|
#to_s ⇒ Object
Return the name of an enum.
Ruby usage:
- @verbatim Enum#to_s @endverbatim
211 212 213 214 215 216 217 218 |
# File 'ext/RMagick/rmenum.c', line 211
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));
}
|