class Binding
Extension methods for {Binding}
Public Instance Methods
call_block(*args, &block)
click to toggle source
Experimental “adaptive” call from local variable names.
# 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)
click to toggle source
Calls {NRSER.template} with `self` prepended to `*args`
@param (see NRSER.erb) @return (see NRSER.erb)
# 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
Also aliased as: template
local_values()
click to toggle source
Get a {Array} of all local variable values.
@return [Array<Object>]
# File lib/nrser/core_ext/binding.rb, line 40 def local_values self.local_variables.map { |symbol| local_variable_get symbol } end
locals()
click to toggle source
Get a {Hash} of all local variable names (as {Symbol}) to values.
@return [Hash<Symbol, Object>]
# File lib/nrser/core_ext/binding.rb, line 31 def locals self.local_variables.assoc_to { |symbol| local_variable_get symbol } end