Posted over 3 years ago. Visible to the public.

Delegating an instance method to a class method in Ruby

With ActiveSupport you can say:

Copy
class Robot def self.likes_humans? 'Nope.' end delegate :likes_humans?, to: :class end Robot.likes_humans? # => 'Nope.' Robot.new.likes_humans? # => 'Nope.'
Growing Rails Applications in Practice
Check out our new e-book:
Learn to structure large Ruby on Rails codebases with the tools you already know and love.

Author of this card:

Avatar
Thomas Klemm
Last edit:
over 3 years ago
by Arne Hartherz
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Thomas Klemm to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more