Class: Cmds::ERBContext
- Inherits:
-
BasicObject
- Defined in:
- lib/cmds/erb_context.rb
Instance Method Summary
collapse
Constructor Details
#initialize(args, kwds) ⇒ ERBContext
Returns a new instance of ERBContext.
3
4
5
6
7
|
# File 'lib/cmds/erb_context.rb', line 3
def initialize args, kwds
@args = args
@kwds = kwds
@arg_index = 0
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/cmds/erb_context.rb', line 9
def method_missing sym, *args, &block
if args.empty? && block.nil?
if sym.to_s[-1] == '?'
key = sym.to_s[0...-1].to_sym
@kwds[key] if @kwds[key]
else
if @kwds.key? sym
@kwds[sym]
elsif @kwds.key? sym.to_s
@kwds[sym.to_s]
else
::Kernel.raise ::KeyError.new ::NRSER.squish <<-END
couldn't find keys #{ sym.inspect } or #{ sym.to_s.inspect }
in keywords #{ @kwds.inspect }
END
end
end
else
super sym, *args, &block
end
end
|
Instance Method Details
#arg ⇒ Object
37
38
39
|
# File 'lib/cmds/erb_context.rb', line 37
def arg
@args.fetch(@arg_index).tap {@arg_index += 1}
end
|
#get_binding ⇒ Object
33
34
35
|
# File 'lib/cmds/erb_context.rb', line 33
def get_binding
::Kernel.send :binding
end
|