Class: Orbit::TemplateBinding
- Inherits:
-
Object
- Object
- Orbit::TemplateBinding
show all
- Defined in:
- lib/orbit/template_binding.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of TemplateBinding.
3
4
5
6
7
8
9
|
# File 'lib/orbit/template_binding.rb', line 3
def initialize(hash)
@variables = {}
hash.each do |key, value|
@variables[key.to_sym] = value
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
27
28
29
30
31
32
|
# File 'lib/orbit/template_binding.rb', line 27
def method_missing(method, *args, &block)
if method.to_s[-1] == '='
var_name = method.to_s[0..-2].to_sym
@variables[var_name] = args.first
end
end
|
Class Method Details
.locals(hash) ⇒ Object
11
12
13
|
# File 'lib/orbit/template_binding.rb', line 11
def self.locals(hash)
new(hash).locals
end
|
Instance Method Details
#locals ⇒ Object
15
16
17
|
# File 'lib/orbit/template_binding.rb', line 15
def locals
@variables
end
|
#variables ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/orbit/template_binding.rb', line 19
def variables
binding.tap do |bind|
@variables.each do |key, value|
bind.local_variable_set(key.to_sym, value)
end
end
end
|