module RType::Helper::RObjDelegatable::ClassMethods

Public Instance Methods

delegate_constructor(klass, *methods) click to toggle source
# File lib/r_type/helper/robj_delegatable_class_methods.rb, line 21
def delegate_constructor klass, *methods
  delegate_klass = self

  methods.each do |name|
    self.class.class_eval do
      define_method(name) do |*args, &block|
        delegate_klass.new klass.send(name, *args, &block)
      end
    end
  end
end
delegate_to_R(*from_to) click to toggle source
Calls superclass method
# File lib/r_type/helper/robj_delegatable_class_methods.rb, line 5
def delegate_to_R *from_to
  from_to_hash = from_to.first.is_a?(Hash) \
                   ? from_to.first         \
                   : from_to.inject({}) {|h,x| h[x] = x; h }

  from_to_hash.each do |from, to|
    define_method(from) do |*args, &block|
      if can_delegate_to_R?(*args)
        R[to].call(self, args.first)
      else
        super(*args, &block)
      end
    end
  end
end