Skip to content

Instantly share code, notes, and snippets.

@banister
Forked from myobie/scope.rb
Created September 28, 2010 01:55
Show Gist options
  • Save banister/600268 to your computer and use it in GitHub Desktop.
Save banister/600268 to your computer and use it in GitHub Desktop.
module Scope
module ScopeMethods
def helpers(&block)
self.instance_eval(&block)
block.call
puts "self inside helpers #{self}"
end
end
def scope(path, &block)
(@path_parts ||= []) << path
context = eval('self', block.binding).dup
context.extend ScopeMethods
context.instance_eval(&block)
@path_parts.pop
end
end
include Scope
scope "something" do
helpers do
def foo
"bar inside "
end
end
puts "self inside scope #{self}"
puts foo # => should work
end
puts foo # => should error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment