Class: CodeRunner::Run::RunClassPropertyFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/coderunner/run.rb

Instance Method Summary collapse

Constructor Details

#initialize(the_class) ⇒ RunClassPropertyFetcher

Returns a new instance of RunClassPropertyFetcher.



104
105
106
# File 'lib/coderunner/run.rb', line 104

def initialize(the_class)
	@my_class = the_class
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, value = nil) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/coderunner/run.rb', line 107

def method_missing(method, value=nil)
	if method.to_s =~ /=$/
		raise 'rcps should not be set outside class methods'
		@my_class.instance_variable_set("@"+method.to_s.sub(/=/, ''), value)
	else
		the_class = @my_class
		loop do 
# 					p the_class, method
# 					p the_class.instance_variables
# 					p the_class.instance_variables.map{|v| the_class.instance_variable_get(v)}
			return the_class.instance_variable_get("@"+method.to_s) if the_class.instance_variables.include?(("@"+method.to_s).to_sym)
			the_class = the_class.superclass
			return nil unless the_class
		end
			
	end
end

Instance Method Details

#[](prop) ⇒ Object



125
126
127
# File 'lib/coderunner/run.rb', line 125

def [](prop)
	send(prop.to_sym)
end