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
129 130 131 132 133 134 135 136 137 138 139 |
# File 'ext/RMagick/rmenum.c', line 129
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.
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'ext/RMagick/rmenum.c', line 174
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
“Case equal” operator for Enum.
Ruby usage:
- @verbatim Enum#=== @endverbatim
Notes:
- Yes, I know "case equal" is a misnomer.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'ext/RMagick/rmenum.c', line 102
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
151 152 153 154 155 156 157 158 |
# File 'ext/RMagick/rmenum.c', line 151
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
206 207 208 209 210 211 212 213 |
# File 'ext/RMagick/rmenum.c', line 206
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));
}
|