Last active
April 5, 2017 21:32
-
-
Save just3ws/876178a2964fb4976470cabb5b824a3c to your computer and use it in GitHub Desktop.
Inline vs Nested Ruby Module Declarations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ruby -W2 -v -e ' (ruby-2.2.2@benchprep) wip-simulation-endpoints 9a603b95e ✗ | |
| puts "before" | |
| module Foo | |
| puts "- Foo -" | |
| end | |
| puts "more" | |
| module Foo::Bar | |
| puts "- Foo::Bar -" | |
| end | |
| puts "and more" | |
| module Foo::Bar::Baz | |
| puts "- Foo::Bar::Baz -" | |
| end | |
| puts "after" | |
| ' | |
| # ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14] | |
| # before | |
| # - Foo - | |
| # more | |
| # - Foo::Bar - | |
| # and more | |
| # - Foo::Bar::Baz - | |
| # after |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ruby -W2 -v -e ' (ruby-2.2.2@benchprep) wip-simulation-endpoints 9a603b95e ✗ | |
| puts "before" | |
| module Foo::Bar::Baz | |
| puts "Nope" | |
| end | |
| puts "after" | |
| ' | |
| # ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14] | |
| # before | |
| # -e:3:in `<main>': uninitialized constant Foo (NameError) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Recommended | |
| ruby -W2 -v -e ' (ruby-2.2.2@benchprep) wip-simulation-endpoints 9a603b95e ✗ | |
| puts "before" | |
| module Foo | |
| puts "- Foo -" | |
| module Bar | |
| puts "-- Bar -" | |
| module Baz | |
| puts "--- Baz -" | |
| end | |
| puts "-- Bar -" | |
| end | |
| puts "- Foo -" | |
| end | |
| puts "after" | |
| ' | |
| # ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14] | |
| # before | |
| # - Foo - | |
| # -- Bar - | |
| # --- Baz - | |
| # -- Bar - | |
| # - Foo - | |
| # after |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
building_up_module_declarations.sh depends on the modules already being loaded which can sometimes be inconsistent depending on how the application is loaded. Safer to default with nested module so the module is defined automatically as needed.