Delegating an instance method to a class method in Ruby

Updated . Posted . Visible to the public.

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.'
Last edit
Arne Hartherz
License
Source code in this card is licensed under the MIT License.
Posted to makandra dev (2015-02-11 19:52)