Skip to content

Instantly share code, notes, and snippets.

Created October 22, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/d548488b1c3ad9abde3c to your computer and use it in GitHub Desktop.
Save anonymous/d548488b1c3ad9abde3c to your computer and use it in GitHub Desktop.
Which one do you think makes more sense?
# First version, uses attributes
method flag-is(:$left-align, :$right-align, :$left-inverse, :$right-inverse, :$inverse, :$intra-chr) {
$mask = 0 +| (:left-align ?? 2 !! 0)
+| (:right-align ?? 1 !! 0)
+| (:left-inverse ?? 8 !! 0)
+| (:right-inverse ?? 4 !! 0)
+| (:right-align ?? 16 !! 0)
+| (:intra-chr ?? 32 !! 0);
return ($.flag +& $mask);
}
# Second version, uses exported bit-flags
constant \FL_LEFT_ALIGN is export := 2;
constant \FL_RIGHT_ALIGN is export := 1;
constant \FL_LEFT_INVERSE is export := 8;
constant \FL_RIGHT_INVERSE is export := 4;
constant \FL_INVERSE is export := 16;
constant \FL_INTRA_CHR is export := 32;
method flag-is(Int $mask) {
return ($.flag +& $mask);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment