Class: Bobkit::Scope

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

Instance Attribute Summary collapse

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.



8
9
10
# File 'lib/bobkit/scope.rb', line 8

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) ⇒ Object



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

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

Instance Attribute Details

#scopeObject (readonly)

Returns the value of attribute scope.



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

def scope
  @scope
end

Instance Method Details

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


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

def respond_to_missing?(method_name, include_private = false)
  if (scope.respond_to?(:key?) && scope.has_key?(method_name)) || scope.respond_to?(method_name)
    true
  else
    super
  end
end