Class: Hyraft::Compiler::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/hyraft/compiler/renderer.rb

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Context

Returns a new instance of Context.



85
86
87
88
# File 'lib/hyraft/compiler/renderer.rb', line 85

def initialize(data = {})
  @data = data
  data.each { |k, v| instance_variable_set("@#{k}", v) }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



96
97
98
# File 'lib/hyraft/compiler/renderer.rb', line 96

def method_missing(name, *args)
  @data.key?(name) ? @data[name] : super
end

Instance Method Details

#get_variable(name) ⇒ Object



90
91
92
93
94
# File 'lib/hyraft/compiler/renderer.rb', line 90

def get_variable(name)
  return @data[name.to_sym] if @data.key?(name.to_sym)
  return instance_variable_get("@#{name}") if instance_variable_defined?("@#{name}")
  nil
end

#respond_to_missing?(name) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/hyraft/compiler/renderer.rb', line 100

def respond_to_missing?(name, *)
  @data.key?(name) || super
end