Wednesday, 2 May 2012

define class methods in ruby (private too)

The following syntax could be used for defining the find method itself, but it is mandatory for alias.
class Item
  def self.find(name)
    # ...
  end

  class << self
    alias :search :find
  end

  private_class_method :find # writing it below private is not enough
end

No comments:

Post a Comment