Class: Magick::Enum
Direct Known Subclasses
Instance Method Summary collapse
-
#<=>(other) ⇒ -1, ...
Support Comparable module in Enum.
-
#===(other) ⇒ Boolean
“Case equal” operator for Enum.
-
#initialize(sym, val) ⇒ Magick::Enum
constructor
Initialize a new Enum instance.
-
#to_i ⇒ Numeric
Return the value of an enum.
-
#to_s ⇒ String
Return the name of an enum.
-
#|(another) ⇒ Magick::Enum
Bitwise OR for enums.
Constructor Details
#initialize(sym, val) ⇒ Magick::Enum
Initialize a new Enum instance.
143 144 145 146 147 148 149 150 151 152 153 |
# File 'ext/RMagick/rmenum.c', line 143 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) ⇒ -1, ...
Support Comparable module in Enum.
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) ⇒ Boolean
“Case equal” operator for Enum.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'ext/RMagick/rmenum.c', line 120 VALUE Enum_case_eq(VALUE self, VALUE other) { if (CLASS_OF(self) == CLASS_OF(other)) { MagickEnum *this, *that; Data_Get_Struct(self, MagickEnum, this); Data_Get_Struct(other, MagickEnum, that); return this->val == that->val ? Qtrue : Qfalse; } return Qfalse; } |
#to_i ⇒ Numeric
Return the value of an enum.
161 162 163 164 165 166 167 168 |
# File 'ext/RMagick/rmenum.c', line 161 VALUE Enum_to_i(VALUE self) { MagickEnum *magick_enum; Data_Get_Struct(self, MagickEnum, magick_enum); return INT2NUM(magick_enum->val); } |
#to_s ⇒ String
Return the name of an enum.
236 237 238 239 240 |
# File 'ext/RMagick/rmenum.c', line 236 VALUE Enum_to_s(VALUE self) { return rb_str_new2(rm_enum_to_cstr(self)); } |
#|(another) ⇒ Magick::Enum
Bitwise OR for enums
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'ext/RMagick/rmenum.c', line 207 VALUE Enum_bitwise_or(VALUE self, VALUE another) { VALUE new_enum, cls; MagickEnum *this, *that, *new_enum_data; cls = CLASS_OF(self); if (CLASS_OF(another) != cls) { rb_raise(rb_eArgError, "Expected class %s but got %s", rb_class2name(cls), rb_class2name(CLASS_OF(another))); } new_enum = Enum_alloc(cls); Data_Get_Struct(self, MagickEnum, this); Data_Get_Struct(another, MagickEnum, that); Data_Get_Struct(new_enum, MagickEnum, new_enum_data); new_enum_data->id = rb_to_id(rb_sprintf("%s|%s", rb_id2name(this->id), rb_id2name(that->id))); new_enum_data->val = this->val | that->val; return new_enum; } |