diff options
author | Clement Ho <clemmakesapps@gmail.com> | 2018-01-17 21:01:06 +0000 |
---|---|---|
committer | Clement Ho <clemmakesapps@gmail.com> | 2018-01-17 21:01:06 +0000 |
commit | 195448c28c3a3238126e9e21f7b1abb8f186980e (patch) | |
tree | 0d2d760317e17aeb3a7dc0d74ffc5d1978a00cb0 /doc/development/utilities.md | |
parent | 525b178e5d5cfe127fe2cfc6f211725e6c3089ae (diff) | |
parent | f351cc28c2c878bf491bb0886be65bf35b58b261 (diff) | |
download | gitlab-ce-dispatcher-project-mr-edit.tar.gz |
Merge branch 'master' into 'dispatcher-project-mr-edit'dispatcher-project-mr-edit
# Conflicts:
# app/assets/javascripts/dispatcher.js
Diffstat (limited to 'doc/development/utilities.md')
-rw-r--r-- | doc/development/utilities.md | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/doc/development/utilities.md b/doc/development/utilities.md index 951c3ef85ce..8f9aff1a35f 100644 --- a/doc/development/utilities.md +++ b/doc/development/utilities.md @@ -45,6 +45,51 @@ We developed a number of utilities to ease development. [:hello, "world", :this, :crushes, "an entire", "hash"] ``` +## [`Override`](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/lib/gitlab/utils/override.rb) + +* This utility could help us check if a particular method would override + another method or not. It has the same idea of Java's `@Override` annotation + or Scala's `override` keyword. However we only do this check when + `ENV['STATIC_VERIFICATION']` is set to avoid production runtime overhead. + This is useful to check: + + * If we have typos in overriding methods. + * If we renamed the overridden methods, making original overriding methods + overrides nothing. + + Here's a simple example: + + ``` ruby + class Base + def execute + end + end + + class Derived < Base + extend ::Gitlab::Utils::Override + + override :execute # Override check happens here + def execute + end + end + ``` + + This also works on modules: + + ``` ruby + module Extension + extend ::Gitlab::Utils::Override + + override :execute # Modules do not check this immediately + def execute + end + end + + class Derived < Base + prepend Extension # Override check happens here, not in the module + end + ``` + ## [`StrongMemoize`](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/lib/gitlab/utils/strong_memoize.rb) * Memoize the value even if it is `nil` or `false`. |