Module: RType::Helper::RObjDelegatable::ClassMethods
- Defined in:
- lib/r_type/helper/robj_delegatable_class_methods.rb
Instance Method Summary collapse
Instance Method Details
#delegate_constructor(klass, *methods) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# 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) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# 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 |