Delegating an instance method to a class method in Ruby
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.'
This website uses short-lived cookies to improve usability.