Read more

Delegating an instance method to a class method in Ruby

Thomas Klemm
February 11, 2015Software engineer

With ActiveSupport you can say:

class Robot
  def self.likes_humans?
    'Nope.'
  end

  delegate :likes_humans?, to: :class
end

Robot.likes_humans?
# => 'Nope.'

Robot.new.likes_humans?
# => 'Nope.'
Illustration online protection

Rails professionals since 2007

Our laser focus on a single technology has made us a leader in this space. Need help?

  • We build a solid first version of your product
  • We train your development team
  • We rescue your project in trouble
Read more Show archive.org snapshot
Posted by Thomas Klemm to makandra dev (2015-02-11 20:52)