Class: Clamsy::Tenjin::BaseContext

Inherits:
Object
  • Object
show all
Includes:
ContextHelper, Enumerable
Defined in:
lib/clamsy/tenjin.rb

Overview

base class for Context class

Direct Known Subclasses

Context

Instance Attribute Summary

Attributes included from ContextHelper

#_buf, #_engine, #_layout

Instance Method Summary collapse

Methods included from ContextHelper

#_P, #_decode_params, #_p, #captured_as, #echo, #escape, #import, #start_capture, #stop_capture

Constructor Details

#initialize(vars = nil) ⇒ BaseContext

Returns a new instance of BaseContext.



243
244
245
# File 'lib/clamsy/tenjin.rb', line 243

def initialize(vars=nil)
  update(vars) if vars.is_a?(Hash)
end

Instance Method Details

#[](key) ⇒ Object



247
248
249
# File 'lib/clamsy/tenjin.rb', line 247

def [](key)
  instance_variable_get("@#{key}")
end

#[]=(key, val) ⇒ Object



251
252
253
# File 'lib/clamsy/tenjin.rb', line 251

def []=(key, val)
  instance_variable_set("@#{key}", val)
end

#eachObject



272
273
274
275
276
277
278
279
280
# File 'lib/clamsy/tenjin.rb', line 272

def each()
  instance_variables().each do |name|
    if name != '@_buf' && name != '@_engine'
      val = instance_variable_get(name)
      key = name[1..-1]
      yield([key, val])
    end
  end
end

#key?(key) ⇒ Boolean Also known as: has_key?

Returns:

  • (Boolean)


261
262
263
# File 'lib/clamsy/tenjin.rb', line 261

def key?(key)
  return self.instance_variables.include?("@#{key}")
end

#update(hash) ⇒ Object



255
256
257
258
259
# File 'lib/clamsy/tenjin.rb', line 255

def update(hash)
  hash.each do |key, val|
    self[key] = val
  end
end