Skip to content

Commit

Permalink
pages 49--52. Application and Delegation. The inner self. Where does …
Browse files Browse the repository at this point in the history
…"get" comes from?
  • Loading branch information
crguezl committed Jul 8, 2012
1 parent e69314c commit 00a12d4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
28 changes: 28 additions & 0 deletions chapter3/scope_gates.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# scope gate: sections of code where the context changes. classes, modules and methods are scope gates

require 'sinatra'

outer_self = self

get '/' do
content_type :txt
"outer self = #{outer_self.inspect}, inner self = #{self}\n
self.class.superclass = #{self.class.superclass}
method(:get) = #{method(:get).inspect}
Sinatra::Delegator.methods(false) = #{Sinatra::Delegator.methods(false).inspect}
Sinatra::Delegator.target = #{Sinatra::Delegator.target.inspect}
Sinatra::Application.method(:get) = #{Sinatra::Application.method(:get).inspect}
source_location of get = #{Sinatra::Application.method(:get).source_location}
"
end

# outer self = main, inner self = #<Sinatra::Application:0x007fd52b8fad60>
# Method calls inside routing blocks are sent to an
# instance of the class "Sinatra::Application"
#
# If you refresh the page the object changes: there is a separated instance for
# every request made.
# Sinatra::Application inherits from Sinatra::Base
# Sinatra::Delegator is a mixing extending Object. Methods like "get"
# and "post" are defined by Sinatra::Delegator, but it simply send the same method
# cal to Sinatra::Application which inherits from Sinatra::Base
2 changes: 2 additions & 0 deletions chapter4/running_modular_applications_68_69.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Running Modular Applications. Page 68 and 69.

1.- A way to know where a gem is installed:
$ ruby -e "p Gem::Specification.find_by_name('sinatra').gem_dir"
"/Users/casiano/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2"
Expand Down

0 comments on commit 00a12d4

Please sign in to comment.