aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
Diffstat (limited to 'guides')
-rw-r--r--guides/source/constant_autoloading_and_reloading.md57
-rw-r--r--guides/source/getting_started.md8
-rw-r--r--guides/source/upgrading_ruby_on_rails.md4
3 files changed, 62 insertions, 7 deletions
diff --git a/guides/source/constant_autoloading_and_reloading.md b/guides/source/constant_autoloading_and_reloading.md
index c552f2bfa3..15f2141b99 100644
--- a/guides/source/constant_autoloading_and_reloading.md
+++ b/guides/source/constant_autoloading_and_reloading.md
@@ -1062,6 +1062,8 @@ spots.
### When Constants aren't Missed
+#### Relative References
+
Let's consider a flight simulator. The application has a default flight model
```ruby
@@ -1070,7 +1072,7 @@ class FlightModel
end
```
-that can be overriden by each airplane, for instance
+that can be overridden by each airplane, for instance
```ruby
# app/models/bell_x1/flight_model.rb
@@ -1122,6 +1124,59 @@ module BellX1
end
```
+#### Qualified References
+
+Given
+
+```ruby
+# app/models/hotel.rb
+class Hotel
+end
+
+# app/models/image.rb
+class Image
+end
+
+# app/models/hotel/image.rb
+class Hotel
+ class Image < Image
+ end
+end
+```
+
+the expression `Hotel::Image` is ambiguous, depends on the execution path.
+
+As [we saw before](#resolution-algorithm-for-qualified-constants), Ruby looks
+up the constant in `Hotel` and its ancestors. If `app/models/image.rb` has
+been loaded but `app/models/hotel/image.rb` hasn't, Ruby does not find `Image`
+in `Hotel`, but it does in `Object`:
+
+```
+$ bin/rails r 'Image; p Hotel::Image' 2>/dev/null
+Image # NOT Hotel::Image!
+```
+
+The code evaluating `Hotel::Image` needs to make sure
+`app/models/hotel/image.rb` has been loaded, possibly with
+`require_dependency`.
+
+In these cases the interpreter issues a warning though:
+
+```
+warning: toplevel constant Image referenced by Hotel::Image
+```
+
+This surprising constant resolution can be observed with any qualifying class:
+
+```
+2.1.5 :001 > String::Array
+(irb):1: warning: toplevel constant Array referenced by String::Array
+ => Array
+```
+
+WARNING. To find this gotcha the qualifying namespace has to be a class,
+`Object` is not an ancestor of modules.
+
### Autoloading within Singleton Classes
Let's suppose we have these class definitions:
diff --git a/guides/source/getting_started.md b/guides/source/getting_started.md
index 31f78ba11c..78316c4ca1 100644
--- a/guides/source/getting_started.md
+++ b/guides/source/getting_started.md
@@ -259,9 +259,9 @@ invoke helper
create app/helpers/welcome_helper.rb
invoke assets
invoke coffee
-create app/assets/javascripts/welcome.js.coffee
+create app/assets/javascripts/welcome.coffee
invoke scss
-create app/assets/stylesheets/welcome.css.scss
+create app/assets/stylesheets/welcome.scss
```
Most important of these are of course the controller, located at
@@ -1637,8 +1637,8 @@ This creates five files and one empty directory:
| app/views/comments/ | Views of the controller are stored here |
| test/controllers/comments_controller_test.rb | The test for the controller |
| app/helpers/comments_helper.rb | A view helper file |
-| app/assets/javascripts/comment.js.coffee | CoffeeScript for the controller |
-| app/assets/stylesheets/comment.css.scss | Cascading style sheet for the controller |
+| app/assets/javascripts/comment.coffee | CoffeeScript for the controller |
+| app/assets/stylesheets/comment.scss | Cascading style sheet for the controller |
Like with any blog, our readers will create their comments directly after
reading the article, and once they have added their comment, will be sent back
diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md
index 7ef51b6dc0..51c144993c 100644
--- a/guides/source/upgrading_ruby_on_rails.md
+++ b/guides/source/upgrading_ruby_on_rails.md
@@ -235,8 +235,8 @@ mail = Notifier.notify(user, ...) # Notifier#notify is not yet called at this po
mail = mail.deliver_now # Prints "Called"
```
-This should not result in any noticible differnces for most applications.
-However, if you need some non-mailer methods to be exectuted synchronously, and
+This should not result in any noticeable differences for most applications.
+However, if you need some non-mailer methods to be executed synchronously, and
you were previously relying on the synchronous proxying behavior, you should
define them as class methods on the mailer class directly: