Class: Binding
- Defined in:
- lib/nrser/core_ext/binding.rb,
lib/nrser/labs/core_ext/binding.rb
Overview
Extension methods for Binding
Instance Method Summary collapse
-
#call_block(*args, &block) ⇒ Object
Experimental “adaptive” call from local variable names.
-
#erb(source) ⇒ Object
(also: #template)
Calls NRSER.template with ‘self` prepended to `*args`.
-
#local_values ⇒ Array<Object>
Get a Array of all local variable values.
- #locals ⇒ Hash<Symbol, Object>
Instance Method Details
#call_block(*args, &block) ⇒ Object
Experimental “adaptive” call from local variable names.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/nrser/labs/core_ext/binding.rb', line 5 def call_block *args, &block arg_count = 0 arg_rest = false call_kwds = {} block.parameters.each do |type, name| logger.debug "Processing", type: type, name: name case type when :req, :opt arg_count += 1 when :keyreq, :key if self.local_variable_defined? name call_kwds[name] = self.local_variable_get name end when :rest arg_rest = true end end call_args = if arg_rest args else args[0...arg_count] end logger.debug "CALLING WITH", args: call_args, kwds: call_kwds block.call *call_args, **call_kwds end |
#erb(source) ⇒ Object Also known as: template
Calls NRSER.template with ‘self` prepended to `*args`
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/nrser/core_ext/binding.rb', line 13 def erb source require 'erb' NRSER.filter_repeated_blank_lines( NRSER.with_indent_tagged( NRSER.dedent( source ) ) { |tagged_str| ERB.new( tagged_str ).result( self ) }, remove_leading: true ) end |