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 UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot
Posted by Thomas Klemm to makandra dev (2015-02-11 20:52)