lib/cross-stub/pseudo_class.rb in cross-stub-0.1.3.1 vs lib/cross-stub/pseudo_class.rb in cross-stub-0.1.4
- old
+ new
@@ -8,25 +8,32 @@
@@convertor ||= lambda {|sexp| Ruby2Ruby.new.process(Unifier.new.process(sexp)) }
@@convertor[ParseTree.translate(metaclass, method)] rescue nil
end
def initialize(klass)
- @klass = klass.is_a?(String) ? Object.const_get(klass) : klass
+ @klass = get_class(klass)
@metaclass = (class << @klass ; self ; end)
end
+ def get_class(klass)
+ if klass.is_a?(String)
+ klass.split(/::/).inject(Object) { |const_train, const| const_train.const_get(const) }
+ else
+ klass
+ end
+ end
+
def id
@klass.to_s
end
def method_code(method)
@@translator[@metaclass, method]
end
def replace_method(method, value_or_code)
status = backup_method(method)
- @klass.instance_eval \
- "#{value_or_code}" =~ /^def / ? value_or_code :
+ @klass.instance_eval "#{value_or_code}" =~ /^def / ? value_or_code :
%\def #{method}; Marshal.load(%|#{Marshal.dump(value_or_code)}|) ; end\
status
end
def revert_method(method)