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.



110
111
112
# File 'lib/coderunner/run.rb', line 110

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



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/coderunner/run.rb', line 113

def method_missing(method, value=nil)
  #eputs 'STARTING'
  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)}
      if method.to_s =~ /\?$/
        return false unless the_class
        return true if the_class.instance_variables.include?(("@"+method.to_s.sub(/\?$/,'')).to_sym)
      else
        raise NoMethodError.new("Run class property #{method} not found.") unless the_class
        return the_class.instance_variable_get("@"+method.to_s) if the_class.instance_variables.include?(("@"+method.to_s).to_sym)
      end
        the_class = the_class.superclass
    end
      
  end
end

Instance Method Details

#[](prop) ⇒ Object



137
138
139
# File 'lib/coderunner/run.rb', line 137

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