Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delegate static methods with Ruby on Rails?

How can I use delegate to delegate a static method?

I am trying to do the following

e.g.

class MyThing
  def some_instance_method(a, b)
    something.some_instance_method(a, b)
  end

  def some_static_method(a, b)
    User.some_static_method(a, b)
  end
end

# can you write it this way???

class MyThing
  delegate :some_instance_method, :to => :something
  delegate :some_static_method, :to => User
end
like image 942
user3179047 Avatar asked May 01 '26 06:05

user3179047


1 Answers

class MyThing
  class << self
    delegate :some_static_method, :to => :User
  end
end
like image 75
usha Avatar answered May 02 '26 21:05

usha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!