Class: Bobkit::Scope

Inherits:
Object
  • Object
show all
Includes:
I18nMixin, SlimBridge
Defined in:
lib/bobkit/scope.rb

Instance Method Summary collapse

Methods included from I18nMixin

#l, #t

Methods included from SlimBridge

#render

Constructor Details

#initialize(scope = nil) ⇒ Scope

Returns a new instance of Scope.



6
7
8
# File 'lib/bobkit/scope.rb', line 6

def initialize(scope=nil)
  @scope = scope || {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/bobkit/scope.rb', line 10

def method_missing(method_name, *arguments, &block)
  if @scope.respond_to?(:key?) and @scope.key?(method_name)
    @scope[method_name]
  elsif @scope.respond_to? method_name
    @scope.send method_name, *arguments
  else
    super
  end
end

Instance Method Details

#respond_to?(method_name, include_private = false) ⇒ Boolean Also known as: have?

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
# File 'lib/bobkit/scope.rb', line 20

def respond_to?(method_name, include_private = false)
  if @scope.respond_to?(:key?) and @scope.key?(method_name)
    true
  elsif @scope.respond_to? method_name
    true
  else
    super
  end
end